开发者

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开发者_StackOverflow中文版 more efficient way of putting partials in a loop.


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

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

I couldn't think of anything more Railsy.


Try:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜