Abdul Baig
Abdul Baig

Reputation: 3721

Unpermitted parameters nested_form strong params

I have a dealership_profile which has_many departments and has_one user, as: :profile (polymorphic).

without departments functionality form was working fine for just dealership_profile and user. But going for department i am stuck in params permission.

My permitted params are:

  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

and params which are passed by the form are

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"}

And i get this error:

 Unpermitted parameters: title

I am following this http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast as help for nested forms

Upvotes: 1

Views: 250

Answers (1)

Eyeslandic
Eyeslandic

Reputation: 14910

It seems you're defining department_attributes in a wrong way, it should be done the same way as with 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

Upvotes: 1

Related Questions