metamaps--metamaps/app/controllers/mappings_controller.rb

50 lines
941 B
Ruby
Raw Normal View History

class MappingsController < ApplicationController
2014-10-18 23:26:34 +00:00
2014-07-27 19:57:35 +00:00
respond_to :json
# GET /mappings/1.json
def show
@mapping = Mapping.find(params[:id])
2014-07-27 19:57:35 +00:00
render json: @mapping
end
2014-07-27 19:57:35 +00:00
# POST /mappings.json
def create
2014-07-27 19:57:35 +00:00
@mapping = Mapping.new(params[:mapping])
@mapping.map.touch(:updated_at)
2014-07-27 19:57:35 +00:00
if @mapping.save
render json: @mapping, status: :created
else
render json: @mapping.errors, status: :unprocessable_entity
end
end
2014-07-27 19:57:35 +00:00
# PUT /mappings/1.json
def update
2014-07-27 19:57:35 +00:00
@mapping = Mapping.find(params[:id])
@mapping.map.touch(:updated_at)
2014-07-27 19:57:35 +00:00
if @mapping.update_attributes(params[:mapping])
head :no_content
else
render json: @mapping.errors, status: :unprocessable_entity
end
end
2014-07-27 19:57:35 +00:00
# DELETE /mappings/1.json
def destroy
2014-07-27 19:57:35 +00:00
@mapping = Mapping.find(params[:id])
@map = @mapping.map
2014-07-27 19:57:35 +00:00
@mapping.destroy
@map.touch(:updated_at)
2014-07-27 19:57:35 +00:00
head :no_content
end
end