Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "render @collection" do?

I'm trying to learn Rails better by looking at example applications, and while looking at this line of the source of railscasts.com, I noticed it does this:

<div class="episodes">
    <%= render @episodes %>
  </div>

What exactly is going on here? Why isn't this documented on the render function? Or is it?

like image 718
ryeguy Avatar asked Aug 28 '26 08:08

ryeguy


1 Answers

This is a handy shortcut for doing

<%= render :partial => "episode", :collection => @episodes %>

which is another way of doing

<% for episode in @episodes do %>
  <%= render :partial => "episode", :locals => { :episode => episode }
<% end %>

which is pretty obvious in what it does :)

Hope that makes sense :)

btw it's really surprising I couldn't find the docs for this too.

like image 168
alex.zherdev Avatar answered Aug 30 '26 21:08

alex.zherdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!