2015-11-05 117 views
0

在我_form部分我使另一部分像下面未定義的局部變量或在軌方法'形式」 4.1

<%= render :partial => 'test', :object => @application.type, \ 
       :locals => {:form => form, \ 
       :application_type => "application[type]"} %> 

當我嘗試加載我得到這個錯誤形式

undefined local variable or method `form' for #<#<Class:0x6daf2c8>:0x8dd3c80> 

我測試部分

<%= fields_for application_type, application do |application_f| %> 
    <div> 
     <div> 
     <%= application_f.label :uni_id, "University" %> 
     <%= application_f.collection_select :uni_id, @unis, :id, :check, {:include_blank => true} %> 
     </div> 
    </div> 
    <div>   

<% end %> 

我最近從3.2更新到rails 4.1。它在以前工作,但現在它顯示錯誤。我想這是語法錯誤,但無法解決它。

+1

你似乎並不在部分任何地方使用的形式。什麼是你的渲染部分調用? –

回答

0

也許你需要替換這樣的事情,在您的頂級模板:

<%= render partial: "form", form: form %> 

或像這樣:

<%= render partial: "form", object: form %> 

像這樣的東西(的當地人參數是必需的現在)

<%= render partial: "form", locals: { form: form } %> 
+0

我正在研究一箇舊項目。我沒有找到使用表單。有兩種模型與此模型相關聯,並且autosave = true。 – asdfkjasdfjk

+0

東西必須調用你的表單部分,也許這是另一個部分,也許是頂層視圖,也許它直接從控制器調用某種奇特的方式,但必須有一個調用者。它可能要麼不傳遞表單對象,要麼以錯誤的方式傳遞它。通常你應該從堆棧跟蹤中看到調用者。 –

0

不少錯誤:

<%= render partial: 'test', locals: {form: form }, object: @application %> 

<%= form.fields_for application.type, application do |application_f| %> 
    <div> 
     <div> 
     <%= application_f.label :uni_id, "University" %> 
     <%= application_f.collection_select :uni_id, @unis, :id, :check, {:include_blank => true} %> 
     </div> 
    </div> 
    </div>   
<% end %> 

應該爲你提供正確的語法。

錯誤是降至form變量未被填充。這似乎來自<%= render調用。沒有上下文,我能給的最好的解決方法是應該如何看:

<%= form_for @variable do |form| %> 
    <%= render partial: "test", locals: {form:form}, object: @application %> 
<% end %> 
相關問題