ecoffee/app/controllers/fairy_controller.rb

34 lines
921 B
Ruby

class FairyController < ApplicationController
def mark
instance_id, location = mark_params
instance = Instance.find_by(public_id: instance_id)
fairy = Fairy.new(location: location, instance_id: instance.id)
unless params[:pwd]
fairy.is_suggested = true
end
if fairy.save
new_instance = Instance.includes(:fairies).find(instance.id)
render partial: "instance/fairies", locals: { instance: new_instance }
end
end
def unmark
instance_id, location = mark_params
if params[:pwd]
instance = Instance.find_by(public_id: instance_id)
Fairy.delete_by(instance_id: instance.id, location: location)
new_instance = Instance.includes(:fairies).find(instance.id)
render partial: "instance/fairies", locals: { instance: new_instance }
end
end
def despawn
end
private
def mark_params
params.expect(:instance, :location)
end
end