undefined method `with_indifferent_access' for

hash, ruby, ruby-on-rails

Solution

Are you sure you want to merge the return value of `shared_incident_params` with the hash in `drive_off_incident_params`? That value is probably a `Parameters` object, but you're trying to merge a hash into it. `Parameters` inherits from `ActiveSupport::HashWithIndifferentAccess`, which tries to coerce the other value into the same type when merging.

I guess that what you're trying to do is to extend the rules in `shared_incident_params` when running `drive_off_incident_params`.

Have you tried just doing something like this:

def shared_incident_params
  params.require(:drive_off_incident).permit(*permitted_incident_params)
end

def permitted_incident_params
  [
    :incident_time, 
    :product,
    :amount_cents, 
    :where_from, 
    :where_to, 
    car_attributes: [:brand_id, :model, :color, :body_type, :plates], 
    witness_attributes: [:first_name, :last_name, :email, :phone],
    notes_attributes: [:id, :content]
  ]
end

def drive_off_incident_params
  shared_incident_params
  params.permit(
    person_description_attributes: [
      :height,
      :age, 
      :gender, 
      :nationality, 
      :features, 
      :clothes ]
  )
end

Problem

In my Rails application I trying to merge some params: ``` def shared_incident_params params.require(:drive_off_incident).permit(:incident_time, :product, :amount_cents, :where_from, :where_to, car_attributes: [:brand_id, :model, :color, :body_type, :plates], witness_attributes: [:first_name, :last_name, :email, :phone], notes_attributes: [:id, :content]) end def drive_off_incident_params shared_incident_params.merge(person_description_attributes: [:height, :age, :gender, :nationality, :features, :clothes]) end ``` But this code gives me the following error: ``` NoMethodError: undefined method `with_indifferent_access' for [:height, :age, :gender, :nationality, :features, :clothes]:Array ``` any ideas?

Original source