Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

How to link the liked posts by each user?

General • Asked by Lauro

I just finished with the Liking Posts screencast. All good. I managed to create a User Profile. And now I'm trying to display the liked post by each user.

I currently have this inside my user/show :

<% @user.likes.each do |like| %>

  <h3> <%= link_to like.post.title %></h3>


<% end %>

Its listing each title liked by the user, but its now linking them to path of the post.

Any suggestions on how to solve this? Am I missing something inside the Like controllers?

Thanks (:


Hey Lauro,

link_to requires two parameters, first the name, second the URL you want to point to. You've only passed in the name, so it's not going to link correctly for you. Try passing in a second parameter to get that working:

  <h3> <%= link_to like.post.title, like.post %></h3>

That totally makes sense. Once more, thanks Chris! :)


Always happy to help. :)


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.