undefined method `map' for #<ActionController::Parameters> Rails 5.1

柔情痞子 提交于 2020-07-05 03:02:11

问题


I am upgrading my rails application from 3.2.2 to 5.1.4. I am gettign error on map method by using on params directly. Error:

undefined method `map' for ActionController::Parameters

On following line.

@assignments= params[:assignments].map {|_k, value| Assignment.new(value.merge assignment_params)}

Any alternative to do that in rails 5.1?


回答1:


You can try to convert params to hash by using to_unsafe_h:

@assignments= params[:assignments].to_unsafe_h.map {|_k, value| Assignment.new(value.merge assignment_params)}

Alternatively, you can iterate over params with each:

@assignments=[]
params[:assignments].each{|(_k, value)| @assignments << Assignment.new(value.merge assignment_params)}


来源:https://stackoverflow.com/questions/49514465/undefined-method-map-for-actioncontrollerparameters-rails-5-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!