Skip to content

Instantly share code, notes, and snippets.

@thiagovsk
Created December 18, 2013 14:25
Show Gist options
  • Save thiagovsk/8023187 to your computer and use it in GitHub Desktop.
Save thiagovsk/8023187 to your computer and use it in GitHub Desktop.
# -*- encoding : utf-8 -*-
class PlacesController < ApplicationController
# GET /places
# GET /places.json
def index
@places = Place.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @places }
end
end
# GET /places/1
# GET /places/1.json
def show
@place = Place.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @place }
end
end
# GET /places/new
# GET /places/new.json
def new
@place = Place.new
@type_existing = Type.all.map { |type| type.name }
@type_desired = []
respond_to do |format|
format.html # new.html.erb
format.json { render json: @place }
end
end
# GET /places/1/edit
def edit
@place = Place.find(params[:id])
end
# POST /places
# POST /places.json
def create
@place = Place.new(params[:place])
puts "="*80, params[:destinationSelect].to_s, "="*80
respond_to do |format|
if @place.save
format.html { redirect_to places_url, notice: 'Local criado com sucesso.' }
format.json { render json: @place, status: :created, location: @place }
else
format.html { render action: "new" }
format.json { render json: @place.errors, status: :unprocessable_entity }
end
end
end
# PUT /places/1
# PUT /places/1.json
def update
@place = Place.find(params[:id])
respond_to do |format|
if @place.update_attributes(params[:place])
format.html { redirect_to places_url, notice: 'Local alterado com sucesso.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @place.errors, status: :unprocessable_entity }
end
end
end
# DELETE /places/1
# DELETE /places/1.json
def destroy
@place = Place.find(params[:id])
@place.destroy
respond_to do |format|
format.html { redirect_to places_url }
format.json { head :no_content }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment