1

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

I have tried this but this generates error unexpected ':' expecting ) for in user_attributes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.