Destroying UpVotes on act_as_votable

I have a rails application that works fine with actions_as_votable. Such a button increases the number of columns, and then switches to the un-like button, and this makes it possible to count the number of messages.

My problem is that since I started using the pearl of Public Activity, I can’t find a way to remove the ones I like from the feed. I used the following loop in an activity index view:

<% @activities.each do |activity| %>
    <p>
        <% if activity.trackable %>
            <%= link_to activity.owner.name, activity.owner %>
            <%= render_activity activity %>
        <% end %>
    </p>
<% end %>

When I delete a comment, the entire line in the activity feed “FOO added comment to BAR” disappears. However, since the actions being the voting gem actually create a downward movement rather than destroying the top line, the “FOO like BAR” line still appears, followed by the “FOO unliked BAR”.

Does anyone know how I can find the top point of current_user on a specific post and then destroy it?

Below is the code of my controller, for example, and in contrast to it:

def like
  @ink.create_activity :like, owner: current_user
  @ink.upvote_by current_user

  redirect_to :back
end

def unlike
  @ink.downvote_by current_user

  redirect_to :back
end

thank

+4
source share
3 answers

, , Element119 , isl. .

def like
    @post.create_activity  :like, 
                           owner: current_user,
                           recipient: @post.user
    @post.upvote_by current_user

    redirect_to :back
  end



def unlike
    @post.downvote_by current_user

    @currentUserLikes = PublicActivity::Activity.where(trackable_id: @post.id, owner_id: current_user.id, key: "post.like")
    @currentUserLikes.destroy_all

    redirect_to :back
  end
+2

, , , , " " - ? , , . - , , destroy / destroy_all.

, public_activity, , , , .

trackable_id - :

@activity = PublicActivity::Activity.find_by(trackable_id: (params[:id]), trackable_type: controller_path.classify)
@activity.destroy

, this SO answer.

+2

, , , unvote_by upvotes, downvotes.

+2

All Articles