Bookies
Bookies

Reputation: 55

Activerecord Reputation System Gem - Extra functionality implementation

I am implementing this gem into my website. However I am trying to implement some more functionality. I placed a thumbs up and thumbs down icons that user will click to cast a vote. Then I took it one step further and try to implement a similar voting approach as youtube's system. I want, when a user clicks on the vote up the icon to change color into green.

Fortunately, I found out that someone else tried that too but I am having problems following his instructions. What this guy did is located at Active Record Reputation System - Railscasts and his username is kobaltz.

So when I try to implement this into my project the icon (loaded image) does not change. I constantly see the red image.

I tried to debug and found out that this segment of code is causing the problems

def up_voted_for?(item)
   eval = evaluations.where(target_type: item.class, target_id: item.id).first
   eval.present? && eval.value > 0 ? true : false
end

where the eval in nill after the execution of the code.

So the code for showing the correct image if user voted or not is:

  <% if can? :vote, answers %>
    <% if current_user.up_voted_for?(answers) %>
      <%= image_tag("color_up_arrow.png") %>
    <% else %> 
      <%= link_to image_tag("gray_up_arrow.png"), vote_answer_path(answers, type: "up"), method: "post" %>
    <% end %>
  <% end %>

For giving a clear picture of all the code, the evaluations are in the user.rb file:

has_many :evaluations, class_name: "RSEvaluation", as: :source

Please let me know of your thoughts. If there is need of any other information please let me know.

p.s. there is no error logs, just the incorrect image loads up.

Thank you for your effort and time!

Upvotes: 1

Views: 294

Answers (1)

Bookies
Bookies

Reputation: 55

Update: found the solution for this one. The developers of this gem updated the evaluation.rb file and as a result the query sent was wrong. You either correct the query you send or use the old version (1.5.1).

Thanks to all which tried to help.

Upvotes: 2

Related Questions