Ruby on rails 使用默认值的Rails方法

Ruby on rails 使用默认值的Rails方法,ruby-on-rails,Ruby On Rails,我在application_helper.rb文件中有helper函数: 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

我在application_helper.rb文件中有helper函数:

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\u category\u id”。当我删除默认值时,我得到了一个错误:参数数量错误(1代表2)。我做错了什么?

您的问题似乎是您必须将cn传递给定期呼叫:

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

属性的类型是什么?