Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to link the liked posts by each user?

Lauro asked in General

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 (:

Reply

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>
Reply

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

Reply

Always happy to help. :)

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.