简体   繁体   中英

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

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?

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)}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM