开发者

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

开发者 https://www.devze.com 2023-02-10 07:10 出处:网络
I\'ve got a partial in a loop like so... <% things.each do |thing| %><%= render :partial => \"thingy\", :locals => { :something=> something, :thing=> thing } %><% end %>

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

精彩评论

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