0

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

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)。我做错了什么?

4

1 回答 1

1

Your problem seems you have to pass cn to recurring call:

raw(attribute.name+nested_attributes(sub_attributes, cn))
于 2013-07-15T00:06:41.530 回答