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

あなたの問題は、繰り返し呼び出しに cn を渡す必要があるようです:

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