find_all_by_ {attribute}不适用于activerecord 4.1.5

时间:2014-10-22 03:59:28

标签: ruby-on-rails rails-activerecord

我正在使用find_all_by从活动记录中获取返回的数组,此功能适用于Rails(4.0.0)

Loading production environment (Rails 4.0.0)
2.0.0-p353 :001 > Subscription.find_all_by_id 123
=> []

但当我将其更改为Rails(4.1.5)时,find_all_by不起作用,并抛出未定义的方法错误

Loading production environment (Rails 4.1.5)
2.0.0-p481 :001 > Subscription.find_all_by_id 123
NoMethodError: undefined method `find_all_by_id' for #<Class:0x00000004d71b68>
    from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.5/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
    from (irb):1
    from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/console.rb:90:in `start'
    from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'

有任何想法可以解决它或解决它吗?

1 个答案:

答案 0 :(得分:0)

这个怎么样?

Subscription.where(id: "123").to_a