Class: FavoritesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
# File 'app/controllers/favorites_controller.rb', line 4

def create
  Favorite.create!({user: current_user, favoriteable: model}, without_protection: true) unless current_user.favorites.find_by_favoriteable_id_and_favoriteable_type(model.id, model.class)
  render nothing: true
end

#destroyObject

Raises:

  • (ActiveRecord::RecordNotFound)


8
9
10
11
12
13
# File 'app/controllers/favorites_controller.rb', line 8

def destroy
  favorite = current_user.favorites.find(params[:id])
  raise ActiveRecord::RecordNotFound if favorite.favoriteable != model
  favorite.destroy
  render nothing: true
end