app/controllers/locations_controller.rb
class LocationsController < ApplicationController
# GET /locations
# GET /locations.json
def index
@locations = Location.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @locations }
end
end
# GET /locations/1
# GET /locations/1.json
def show
@location = Location.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @location }
end
end
# GET /locations/new
# GET /locations/new.json
def new
@location = Location.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @location }
end
end
# GET /locations/1/edit
def edit
@location = Location.find(params[:id])
end
# POST /locations
# POST /locations.json
def create
@location = Location.new(params[:location])
respond_to do |format|
if @location.save
format.html {
flash[:success] = 'Location was successfully created.'
redirect_to @location
}
format.json { render json: @location, status: :created, location: @location }
else
format.html { render action: "new" }
format.json { render json: @location.errors, status: :unprocessable_entity }
end
end
end
# PUT /locations/1
# PUT /locations/1.json
def update
@location = Location.find(params[:id])
respond_to do |format|
if @location.update_attributes(params[:location])
format.html {
flash[:success] = 'Location was successfully updated.'
redirect_to @location
}
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @location.errors, status: :unprocessable_entity }
end
end
end
# DELETE /locations/1
# DELETE /locations/1.json
def destroy
@location = Location.find(params[:id])
@location.destroy
respond_to do |format|
format.html { redirect_to locations_url }
format.json { head :ok }
end
end
end