Class: LikesController

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

Instance Method Summary collapse

Instance Method Details

#createObject


7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/likes_controller.rb', line 7

def create
  like.topic = topic
  like.user = current_user
  if topic.already_liked?(current_user)
    flash[:alert] = t("flash.double_like")
  elsif like.save
    flash[:notice] = t("flash.liked")
  else
    flash[:alert] = like.errors.full_messages.join(' ')
  end
  redirect_to topic_path(topic)
end

#destroyObject


20
21
22
23
24
25
26
27
# File 'app/controllers/likes_controller.rb', line 20

def destroy
  if topic.already_liked?(current_user) && like.destroy
    flash[:notice] = t("flash.unliked")
  else
    flash[:alert] = like.errors.full_messages.join(' ')
  end
  redirect_to topic_path(topic)
end