在我的主模板,我有以下幾點:錯誤渲染的部分(ROR)時傳遞的形式爲局部變量
<%= render :partial => "delivery_date", :collection => @brand.delivery_dates, :locals => {:form => f} %>
然而,當局部嘗試使用方式的局部變量,我得到這個錯誤
Showing app/views/brands/_delivery_date.html.erb where line #2 raised:
wrong number of arguments (0 for 1)
Extracted source (around line #2):
1: <%= delivery_date.id %>
2: <%= form.text_field :name %>
3: <% new_or_existing = delivery_date.new_record? ? 'new' : 'existing' %>
4: <% prefix = "brand[#{new_or_existing}_delivery_date_attributes][]" %>
5: <% fields_for prefix, delivery_date do |dd_f| %>
有誰明白這是什麼錯誤意味着?
其實我想做
<% form.fields_for delivery_date do |dd_f| %>
,但還是失敗,那麼。
我試着用:locals => { :f => f }
代替:locals
,並在部分代碼中使用了f
。沒有影響,那麼錯誤是undefined method or variable f
。
...
好,而不是要求您調試錯誤,問題是怎麼也呈現fields_for在嵌套部分形式:
在主模板:
<% form_for @object do |f| %>
<% render :partial => 'child', :collection: @object.child %>
<% end %>
在子模板中:
<% form.fields_for child do |c_f| %>
<%= c_f.text_field :foo %>
<% end %>
傳遞此表單的合適方法是什麼目的?
對不起忘了補充環境:
的Ruby 1.8.7
Rails的2.3? (要回去看看小版本,沒有在我面前的代碼)
(我知道這是一個新手的問題:()
:locals => {:x => 2}起作用。 事實上,我意識到自從我在link_to_function中渲染此模板時,可能是因爲我沒有完全查看錯誤堆棧,並且錯過了錯誤來源。我認爲這有助於:我將繼續保持它。謝謝。 – 2010-03-19 19:39:57