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

58 lines
1.2 KiB
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
@mapping = Mapping.new(mapping_params)
@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)
if @mapping.update_attributes(mapping_params)
2014-07-27 19:57:35 +00:00
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
2015-09-19 08:26:34 +00:00
private
# Never trust parameters from the scary internet, only allow the white list through.
def mapping_params
params.require(:mapping).permit(:id, :category, :xloc, :yloc, :topic_id, :synapse_id, :map_id, :user_id)
end
end