2013-07-14 47 views
0

我在application_helper.rb文件辅助函数:Rails的默认值的方法

def nested_attributes(attributes, cn = controller_name.classify) 
    attributes.map do |attribute, sub_attributes| 
     content_tag(:ul) do 
      content_tag(:li, :id => cn+"[#{attribute.id}]") do 
       raw(attribute.name+nested_attributes(sub_attributes)) 
      end 
     end 
    end.join.html_safe 
end 

,然后我从视图中调用它:

<%= nested_attributes @categories.arrange, 'baget_category_id' %> 

但是,当我检查结果,我得到了控制器名称(这是默认值)而不是'baget_category_id'。当我删除默认值时,我得到一个错误:参数的错误数量(1为2)。我做错了什么?

+0

什么是'attribute'的类型? – vee

+0

属性 - 是数组 – Roman

回答

1

你的问题似乎你要通过cn来重复呼叫:

raw(attribute.name+nested_attributes(sub_attributes, cn))