CafeHey
CafeHey

Reputation: 5800

Rails and partials, is there a more efficent way of writing this...?

I've got a partial in a loop like so...

<% things.each do |thing| %><%= render :partial => "thingy", :locals => { :something  => something, :thing  => thing } %><% end %>

This just doesn't seem very railsy, I was wondering if there more efficient way of putting partials in a loop.

Upvotes: 6

Views: 210

Answers (2)

user142019
user142019

Reputation:

Rename your partial from 'thingy' to 'thing' and do this:

<%= render things, :locals => { :something => :goatse } %>

I couldn't think of anything more Railsy.

Upvotes: 5

apneadiving
apneadiving

Reputation: 115531

Try:

<%= render :partial => "thingy", :collection =>things, :locals => { :something  => something} %>

Upvotes: 2

Related Questions