Ask A Question

Notifications

You’re not receiving notifications from this thread.

I didn't understand this part of the Liking Posts

Maor Tzabari asked in Rails
<div id="likes">
  <%= render partial: "likes" %>
</div>

we render something here, but where is this partial?
usually when I render something with Rails it's a form or other code that exist
but what are we rendering here?

Reply

You can render any partial you want, Rails just provides a lot of helpful shortcuts when you pass in ActiveRecord objects. Here we're rendering one called app/views/posts/_likes.html.erb. Since this is being rendered inside a Post view, it looks in the posts folder for the partial file although you could specify any folder you wanted.

You have to create that partial, it's not one that will be autogenerated for you, and we do this for organization of your code. You can reuse that partial in other places if you want and it will output the same HTML.

All the final code you can find here: https://github.com/gorails-screencasts/gorails-24-liking-posts

Reply

I actually haven't noticed that you created the _likes partial
I'll watch again, thank you for the quick reply!

Reply
Join the discussion
Create an account Log in

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

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

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