2010-10-26 64 views
0

我正在嘗試從解析的json(哈希表單)生成一個表單,使用此幫助程序幫助程序的參數數量錯誤

def hash_to_form(hash, fields, legend) 
    fields.fields_for do |b| 
     concat('<fieldset><legend>', legend, '</legend>') 
     hash.each do |key, attr| 
     if hash[key].is_a? Hash 
      hash_to_form(hash[key], b, key) 
     else 
      concat("<div class=\"field\">") 
      concat(b.label(key, key)) 
      concat(b.text_field(key, :value => attr)) 
      concat("</div>") 
     end 
     end 
    end 
    end 

但是當我嘗試調用幫助程序方法時,它會給我一個錯誤的參數個數(0表示1) 。這是沒有意義的,因爲它需要3個參數?

回答

2

這不是你的幫手具有錯誤的參數數目,這是你的fields_for電話:

fields.fields_for do |b| 

這個方法取一個名字相關聯。如果用戶模型的has_many地址,調用該方法是這樣的:

f.fields_for :addresses do |address_fields| 

修復這應該解決您的幫手。