lundi 30 janvier 2017

acts_as_votable gem likes all the posts on page in rails

Lemme explain what I mean, the point is that I am using acts_as_votable gem in my rails app and it works fyn, problem is that I am using ajax and I am using it to like individual posts from my index page . I will explain with the code

This is my @confessions controller instance variable that has all the votes

 @confessions = Confession.where(amitian_id: ids).order('created_at DESC')

Now this is my view that shows all the posts

  -@confessions.each do |c|
  # code  
  c.get_upvotes.size , remote: true
  c.get_downvotes.size, remote: true
  end

Well, up until now I can use 'c' variable to refer to a single post.. but in my ajax script I have something like this

  $('.like').html('<%=  pluralize(@confessions.get_upvotes.size,"Like") %>');
  $('.dislike').html('<%=  pluralize(@confessions.get_downvotes.size,"Dislike") %>');

Now obviously, this will like all the post variable @confessions have.. how can i write a script to make it like the post user clicks on I suppose I have to use this or self keyword but m not sure how.. help plz

Aucun commentaire:

Enregistrer un commentaire