2012-01-08 64 views
2

下面是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. 

沒有關於什麼是當地人在這裏的目的解釋?什麼是當地人?

謝謝。

回答

2

例如,

  1. < %= render :partial => "account" %>

    這意味着已經有一個名爲@account一個實例變量的部分,你通過。

  2. <%= render :partial => "account", :locals => { :account => @buyer } %>

    這意味着你通過所謂@buyer到「帳戶」部分的本地實例變量,並在「賬戶」變量部分被稱爲「帳戶」。換句話說,散列{ :account => @buyer }用於:locals僅用於將局部變量傳遞給partial。你也可以用相同的方式使用關鍵字。

<%= render :partial => "contract", :as => :agreement

這是一樣的:

<%= render :partial => "contract", :locals => { :agreement => @contract }