Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes undefined method `map!' for ActiveRecord_Relation?

I am updating from Rails 3 to Rails 4.2, and when I run my application's test suite, I get the following error:

 Failure/Error: get 'edit', id: @shops[3].id
 NoMethodError:
   undefined method `map!' for #<Shop::ActiveRecord_Relation:0x007ff1d69b4f40>

The code in the controller is:

existing_shops.map! { |obj| [["##{obj[:shop_id]} #{obj[:name]},
#{obj[:phone]}, #{obj[:address]}, #{obj[:city]}, #{obj[:state]}, #{obj[:zipcode]} "]]}

I am using Rails 4.2.4 and RSpec 3.3.0.

like image 723
Fi3n1k Avatar asked Nov 27 '25 15:11

Fi3n1k


1 Answers

Relation no longer has mutator methods like #map! and #delete_if. Convert to an Array by calling #to_a before using these methods.

existing_shops.to_a.map! { ... }

— A Guide for Upgrading Ruby on Rails

like image 129
jibiel Avatar answered Nov 30 '25 06:11

jibiel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!