diff --git a/app/controllers/reactions_controller.rb b/app/controllers/reactions_controller.rb index bf3ed62ec..cb64057ee 100644 --- a/app/controllers/reactions_controller.rb +++ b/app/controllers/reactions_controller.rb @@ -48,26 +48,31 @@ class ReactionsController < ApplicationController reactable_type: params[:reactable_type], category: category, ).first + result = "" if reaction current_user.touch reaction.destroy Moderator::SinkArticles.call(reaction.user_id) if vomit_reaction_on_user?(reaction) Notification.send_reaction_notification_without_delay(reaction, reaction.reactable.user) Notification.send_reaction_notification_without_delay(reaction, reaction.reactable.organization) if organization_article?(reaction) - @result = "destroy" + result = "destroy" else - reaction = Reaction.create!( + reaction = Reaction.new( user_id: current_user.id, reactable_id: params[:reactable_id], reactable_type: params[:reactable_type], category: category, ) - @result = "create" - Moderator::SinkArticles.call(reaction.user_id) if vomit_reaction_on_user?(reaction) - Notification.send_reaction_notification(reaction, reaction.reactable.user) - Notification.send_reaction_notification(reaction, reaction.reactable.organization) if organization_article?(reaction) + if reaction.save + result = "create" + Moderator::SinkArticles.call(reaction.user_id) if vomit_reaction_on_user?(reaction) + Notification.send_reaction_notification(reaction, reaction.reactable.user) + Notification.send_reaction_notification(reaction, reaction.reactable.organization) if organization_article?(reaction) + else + return render json: { error: reaction.errors.full_messages.join(", "), status: 422 }, status: :unprocessable_entity + end end - render json: { result: @result, category: category } + render json: { result: result, category: category } end def cached_user_positive_reactions(user) diff --git a/app/views/articles/_actions.html.erb b/app/views/articles/_actions.html.erb index 3d0063b70..c2639a985 100644 --- a/app/views/articles/_actions.html.erb +++ b/app/views/articles/_actions.html.erb @@ -1,20 +1,22 @@
- - - - - " alt="twitter logo"> - + <% if @article.published? %> + + + + + " alt="twitter logo"> + + <% end %> DISCUSS <% if @article.comments_count.positive? %>