Gerome John Pangan Gerome John Pangan - 4 months ago 9
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 %>
<td>
<%= link_to 'unlike', {:controller => 'post', :id => post , :action =>'unlike'}, class: "btn btn-xs btn-danger" %>
</td>
<% else %>
<td>
<%= link_to 'like', {:controller => 'post', :id => post , :action =>'like'}, class: "btn btn-xs btn-danger" %>
</td>
<% end %>


and this give me an error

but in my rails console is working:

1

Answer

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

<% if current_user.liked? post %>
Comments