I want to make some styling changes if user has voted for a photo, and I used this code (acts_as_votable docs):
<% if current_user.voted_for? @photo %>
<%= link_to like_photo_path(@photo), method: :put do %>
<button>
¡Liked!
</button>
<% end %>
<% else %>
You dont like it yet
<% end %>
But this wont work because it will show "Liked" all the time, even if I didn't click the Like button.
photos controller
def upvote
@photo = Photo.friendly.find(params[:id])
@photo.liked_by current_user
redirect_to user_photo_path(@photo.user,@photo)
end
What can it be wrong?