All threads / How to link the liked posts by each user?

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

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! :)

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.