0

I am trying to execute following line in rails console (bundle exec rails c):

query = select("product.id").where("admin_id = ? and account_id = ?", 3, 4)

But I get following error:

TypeError: wrong argument type String (expected Array)
from (irb):83:in `select'

This code seems to be working fine in the application as such. Any clue on why it is failing in irb?


ruby version -> 1.9.3p545
Rails version -> 3.2.8


This code is originally defined in a ActiveRecord class (Product) in a scope. How to execute it through rails console ?

1
  • irb or rails console. Also what context are you executing it in. It seems you want to call it in a context of some ActiveRecord class, you are missing a receiver here. Commented Jun 4, 2014 at 12:44

1 Answer 1

5

You haven't specified the receiver for select, hence it tries to execute select method defined on Kernel module. In your application this call is wrapped within some class, which becomes a default receiver. You need to add this receiver to your call in irb, most likely:

query = Product.select("product.id").where("admin_id = ? and account_id = ?", 3, 4)

Update:

Since this is defined as a scope, you can just use scope name to execute it:

query = Product.scope_name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.