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

52 lines
1,012 B
Ruby
Raw Normal View History

class MappingsController < ApplicationController
2014-07-27 19:57:35 +00:00
before_filter :require_user, only: [:create, :update, :destroy]
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