我有一个brokerhip_profile,其中包含多个部门和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作为嵌套表单的帮助
答案 0 :(得分: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