Rails: Should partials be aware of instance variables?

前端 未结 4 1191
渐次进展
渐次进展 2020-12-07 13:05

Ryan Bates\' nifty_scaffolding, for example, does this

edit.html.erb

<%= render :partial => \'form\' %>

new.html.erb

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 13:34

    You can have it both ways. At the top of your partial:

    <% item ||= @item %>
    

    That way, it works with or without passing the local variable, providing a sane default, but not inhibiting alternate usage of the partial.

提交回复
热议问题