Gerome John Pangan Gerome John Pangan - 1 year ago 54
Ruby Question

undefined method `likes?' for #<User:0x007fa57a66ba80>

I have been installed acts_as_votable gem for my web application. I have separate button for like and unlike. then i want to merge them to be more beautiful. So i create an if condition

<% if current_user.likes? post %>
<%= link_to 'unlike', {:controller => 'post', :id => post , :action =>'unlike'}, class: "btn btn-xs btn-danger" %>
<% else %>
<%= link_to 'like', {:controller => 'post', :id => post , :action =>'like'}, class: "btn btn-xs btn-danger" %>
<% end %>

and this give me an error

but in my rails console is working:


Answer Source

According to this, it's liked? not likes?:

<% if current_user.liked? post %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download