Class: LikesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/likes_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Methods included from Voluntary::V1::BaseController

#parent, #voluntary_application_javascripts, #voluntary_application_stylesheets

Methods included from Applicat::Mvc::Controller

included

Instance Method Details

#createObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/likes_controller.rb', line 2

def create
  positive = request.original_url.match('/like/') ? true : false
  like_or_dislike = current_user.likes_or_dislikes.where(target_type: params[:target_type], target_id: params[:target_id]).first
  
  if like_or_dislike
    like_or_dislike.update_attribute(:positive, positive)
  else
    current_user.likes_or_dislikes.create!(positive: positive, target_type: params[:target_type], target_id: params[:target_id])
  end
  
  render nothing: true
end

#destroyObject

Raises:

  • (ActiveRecord::RecordNotFound)


15
16
17
18
19
20
21
22
# File 'app/controllers/likes_controller.rb', line 15

def destroy
  like_or_dislike = current_user.likes_or_dislikes.where(target_type: params[:target_type], target_id: params[:target_id]).first
  
  raise ActiveRecord::RecordNotFound unless like_or_dislike
  
  like_or_dislike.destroy!
  render nothing: true
end