0

This:

User.where 'id < ?', 5

fails with this message:

NoMethodError: undefined method `join' for #<Class:0x007fa4c9b5a598>

When I try:

User.where 'id < 5'

it works.

In another project:

User.where 'id < ?', 5

works.

Where could be my problem?

Update

I could solve the problem but commenting a gem:

# gem 'cancan'

Working flow

Then when I run console, I get:

load error: ~/.irbrc
NameError: uninitialized constant ApplicationController::CanCan

And my simple query works.

Not working flow

Then I comment CanCan part of application controller and console starts without problems, but when I try my simple query it fails with the same error.

What I am trying now

Searching for join in ~/.irbrc, I got several results. But I am not sure of what I am doing.

Where could be my problem?

sites
  • 21,417
  • 17
  • 87
  • 146
  • 2
    Can you post your model? There may be some clues in the scopes/associations. – Matt May 19 '13 at 23:31
  • I agree. It sounds like a default scope of some sort. – Han May 20 '13 at 00:02
  • 1
    Try searching for `join` in your model code. If you find it replace it with `joins`. – Mischa May 20 '13 at 00:05
  • Is a legacy code, and I can't share it, I signed a contract, there is no `scope`, neither `join` words, neither class methods. – sites May 20 '13 at 00:11
  • It fails in the same line as this question http://stackoverflow.com/questions/16364347/dynamic-matchers-rb55in-method-missing-undefined-method-migration-error – sites May 20 '13 at 00:22
  • I commented all code in user model, and same problem. – sites May 20 '13 at 00:42

2 Answers2

2

Not really an answer to your question, but I personally try to use as little straight SQL as possible in my code.

Check out the squeel gem, which will help with this, especially this kind of query. https://github.com/ernie/squeel

sites
  • 21,417
  • 17
  • 87
  • 146
cpuguy83
  • 5,794
  • 4
  • 18
  • 24
0

I had this snippet in my ~/.irbrc

203   # instead of User.find(...) you can do user(...)
204   #   without arguments it only returns the model class
205   #   based on http://www.clarkware.com/blog/2007/09/03/console-shortcut
206 #  Dir.glob( File.join(Dir.pwd, *%w<app models ** *.rb>) ).map { |file_name|
207 #    table_name = File.basename(file_name).split('.')[0..-2].join

I commented all the block and now it works. Well, I copied that file and never have understood it.

sites
  • 21,417
  • 17
  • 87
  • 146