0

I just recently upgraded to Rails 5.1.7 I have this controller:

def profile_setting_preview
  profile_setting_preview_params[:content].map{ |c| ap c }
  // do something else
end

private

def profile_setting_preview_params
  params.require(:profile_setting).permit(content: {
    title: [ :content, merge_tag_blocks: [] ],
    header: [ :content, merge_tag_blocks: [] ],
    blocks: [ :content, merge_tag_blocks: [] ],
    footer: [ :content, merge_tag_blocks: [] ],
  })
end

When I call this controller, I get the error:

undefined method `map' for 
#<ActionController::Parameters:0x00007f9030d2d8c8>

Why is this happening for filtered params? I thought I am filtering it properly and thus it should be able to be converted to hash.

nanakondor
  • 615
  • 11
  • 25
  • Did you try https://apidock.com/rails/ActionController/Parameters/to_unsafe_h or `each` instead? – Kevin Etore Jun 16 '20 at 06:49
  • Possible duplicate of https://stackoverflow.com/questions/49514465/undefined-method-map-for-actioncontrollerparameters-rails-5-1 – ricks Jun 16 '20 at 14:34

1 Answers1

0

You could change it to hash first

profile_params = profile_setting_preview_params.to_h
profile_params[:content].map{ |c| ap c }

Reference:

Since in Rails 5, ActionController::Parameters will no longer inherit from HashWithIndifferentAccess.