下面是render的API定义:
render(options = {}, locals = {}, &block)
Returns the result of a render that’s dictated by the options hash. The primary options are:
:partial - See ActionView::Partials.
:file - Renders an explicit template file (this used to be the old default), add :locals to pass in those.
:inline - Renders an inline template similar to how it’s done in the controller.
:text - Renders the text passed in out.
没有解释当地人在这里的目的是什么?当地人是做什么的?
谢谢。
发布于 2012-01-08 16:52:33
例如:
<%= render :partial => "account" %>
这意味着partial已经有一个名为@account
的实例变量,您可以将其传递给partial.
<%= render :partial => "account", :locals => { :account => @buyer } %>
这意味着您将一个名为@buyer
的本地实例变量传递给account
partial,而account
partial中的变量称为@account
。也就是说,:locals
的散列{ :account => @buyer }
仅用于将局部变量传递给partial。您也可以以相同的方式使用关键字as
:
<%= render :partial => "contract", :as => :agreement
这与以下内容相同:
<%= render :partial => "contract", :locals => { :agreement => @contract }
发布于 2012-01-08 16:34:01
将局部变量传递给部分模板,而不是控制器实例变量。
请参阅Section 3.4.4, Passing Local Variables in the Layouts and Rendering Guide.
https://stackoverflow.com/questions/8779175
复制相似问题