Class: Hyrax::TrophiesController

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

Instance Method Summary collapse

Instance Method Details

#toggle_trophyObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/hyrax/trophies_controller.rb', line 5

def toggle_trophy
  work_id = params[:id]
  t = current_user.trophies.where(work_id: work_id).first
  if t
    authorize!(:destroy, t)
    t.destroy
  else
    t = current_user.trophies.build(work_id: work_id)
    authorize!(:create, t)
    t.save!
  end
  render json: t
end