Class: Sufia::TrophiesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/sufia/trophies_controller.rb

Instance Method Summary collapse

Instance Method Details

#toggle_trophyObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/sufia/trophies_controller.rb', line 3

def toggle_trophy
  work_id = params[:id]
  authorize! :edit, work_id
  t = current_user.trophies.where(work_id: work_id).first
  if t
    t.destroy
    return false if t.persisted?
  else
    t = current_user.trophies.create(work_id: work_id)
    return false unless t.persisted?
  end
  render json: t
end