David B. David B. - 8 months ago 19
Ruby Question

Rails 3: can't call an ActiveRecord querry with the #send method (NoMethodError)

In the rails console I get those results:

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'

But when I type the method directly:

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

How come the #find_by_shop_id cant be "sent" ?



The method you're trying to execute is called find_by_shop_id not find_by_shop_id(2). The send method expects a method name, followed by the parameters. E.g.,

Employee.send "find_by_shop_id", 2