gpt4 book ai didi

ruby-on-rails - 是什么导致 ActiveRecord_Relation 的未定义方法 `map!'?

转载 作者:行者123 更新时间:2023-12-05 08:57:23 35 4
gpt4 key购买 nike

我正在从 Rails 3 更新到 Rails 4.2,当我运行应用程序的测试套件时,出现以下错误:

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

Controller 中的代码是:

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

我正在使用 Rails 4.2.4 和 RSpec 3.3.0。

最佳答案

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

关于ruby-on-rails - 是什么导致 ActiveRecord_Relation 的未定义方法 `map!'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33346492/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com