All threads / I didn't understand this part of the Liking Posts

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?

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

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

Join the discussion

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

Join 33,665+ 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.