gpt4 book ai didi

ruby-on-rails - rails 3 : can't call an ActiveRecord query with the #send method (NoMethodError)

转载 作者:数据小太阳 更新时间:2023-10-29 08:30:41 26 4
gpt4 key购买 nike

在 Rails 控制台中,我得到了这些结果:

Employee.send("find_by_shop_id(2)")
NoMethodError: undefined method `find_by_shop_id(2)' for <Class:0x000000032f75d0> from /var/lib/gems/1.9.1/gems/activerecord 3.1.4/lib/active_record/base.rb:1088:in `method_missing'

但是当我直接输入方法时:

Employee.find_by_shop_id(2)
=> #<Employee id: 2, first_name: "Roger", last_name: "Bartoletti", email: "marilie_hane@harris.biz", shop_id: 2>

#find_by_shop_id 为什么不能“发送”?

谢谢

最佳答案

您尝试执行的方法称为 find_by_shop_id 而不是 find_by_shop_id(2)send方法需要一个方法名称,后跟参数。例如,

Employee.send "find_by_shop_id", 2

关于ruby-on-rails - rails 3 : can't call an ActiveRecord query with the #send method (NoMethodError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37745961/

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