问题
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