如何使用强参数gem允许自定义参数?

时间:2015-01-12 05:30:23

标签: ruby-on-rails ruby ruby-on-rails-3 strong-parameters

我按照以下方式获得参数。

 {"utf8"=>"✓", "authenticity_token"=>"auth_token=", "js_data_entry"=>[{"data_entry"=>[{"name"=>"test_book22", "node_id"=>"65", "field_type"=>"Text", "options_attributes"=>[{"option_value"=>""}], "location"=>"Body", "rank"=>"", "must_fill"=>"0", "multi"=>"0", "role"=>["4"], "update_db"=>"vocation.name", "select_db"=>""}], "js_editor"=>[{"field_id"=>"", "field_class"=>"", "js_code"=>""}]}], "node_id"=>"65", "commit"=>"Submit", "action"=>"create", "controller"=>"data_entries"}

我试图允许params如下

 def entry_params
   params.require(:js_data_entry).permit([:node_id, :field_type, :name, :location, :rank, :multi, :must_fill, :update_db, :select_db, :role, :options_attributes])
 end

但它正在投掷

undefined method `permit' for #<Array:0xc603e78>

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

我修正了以下问题..

 params.require(:js_data_entry)[0].permit(:data_entry=>[:node_id, :field_type, :name, :location, :rank, :multi, :must_fill, :update_db, :select_db, :role=>[], :options_attributes=>[:option_value]], :js_editor=>[:field_id,:field_class,:js_code])