【问题标题】:Unpermitted parameters nested_form strong params不允许的参数nested_form strong params
【发布时间】:2014-05-14 18:54:19
【问题描述】:

我有一个dealership_profile,它有_many 个部门和has_one 用户,如::profile(多态)。

没有部门功能表单仅适用于dealership_profile 和用户。但是去部门我被困在params许可中。

我允许的参数是:

  def dealership_profile_params
    params.require(:dealership_profile).permit(:dealership_name, :dealership_per_hour_cost, :dealership_working_hours, :dealership_group_profile_id, :dealership_depreciation_assumption, { departments_attributes: :department[:title] }, :car_turn_goal, user_attributes: [:id, :first_name, :last_name, :role_id, :username, :crypted_password, :password_salt, :persistence_token, :per_hour_wages, :password, :password_confirmation]) #departments_attributes: [:id, :title]
  end

表单传递的参数是

Parameters: {"utf8"=>"✓", "authenticity_token"=>"bML8iCIyyYQwP2Muo/uZfEERYHpeZDw=", "dealership_profile"=>{"

user_attributes"=>{"first_name"=>"test_dealership8", "last_name"=>"test_dealership8", "username"=>"test_dealership8", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "dealership_name"=>"test_dealership8", "dealership_per_hour_cost"=>"", "dealership_working_hours"=>"", "dealership_depreciation_assumption"=>"", "car_turn_goal"=>"",

"departments_attributes"=>{"0"=>{"title"=>"title"}, "1"=>{"title"=>"title1"}, "2"=>{"title"=>"title2"}, "3"=>{"title"=>""}, "4"=>{"title"=>""}, "5"=>{"title"=>""}, "6"=>{"title"=>""}, "7"=>{"title"=>""}, "8"=>{"title"=>""}, "9"=>{"title"=>""}}}, "commit"=>"Create Dealership profile"}

我得到这个错误:

 Unpermitted parameters: title

我正在关注 http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast 作为嵌套表单的帮助

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 parameter-passing strong-parameters


    【解决方案1】:

    您似乎以错误的方式定义了 department_attributes,应该按照与 user_attributes 相同的方式来完成。

    def dealership_profile_params
        params.require(:dealership_profile).permit(:dealership_name, :dealership_per_hour_cost, :dealership_working_hours, :dealership_group_profile_id, :dealership_depreciation_assumption, departments_attributes: [:title], :car_turn_goal, user_attributes: [:id, :first_name, :last_name, :role_id, :username, :crypted_password, :password_salt, :persistence_token, :per_hour_wages, :password, :password_confirmation]) 
    end
    

    【讨论】:

    • 我已经尝试过了,但这会在 user_attributes 中生成错误 unexpected ':' expecting )
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多