Class: LikesController
Instance Method Summary
collapse
#current_ability
#parent, #voluntary_application_javascripts, #voluntary_application_repository_path, #voluntary_application_stylesheets
included
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|