Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Asset pre-compilation fails when using Devise and named scope with lambda in User model #1373

ljfc opened this Issue · 7 comments

3 participants


Apologies if this is not in fact a problem with Devise, but lib/devise.rb, lib/devise/mapping.rb and lib/devise/rails/routes.rb appear in the backtrace, so I thought it was worth letting you know.

The problem appeared when I added a named scope incorporating a lambda function to the User model that uses devise:
scope :find_by_skill_offered, lambda { |skill_id|
joins(:skills).where("user_skills.offered = ? AND = ?", :true, skill_id)

Now calling rake assets:precompile fails, both locally and on a development server, with the error Could not find table 'users'.

Full backtrace of the rake error here:

I have also asked about this on StackOverflow, as I can see that this may not be a bug in Devise, but I have tried a few workarounds elsewhere relating to other rake tasks failing in the same way, and a similar error relating to factory_girl, but none of them seem to work in this case.


Can you please push to Github a small application that reproduces the error? Also, please include Devise and Rails versions in your reports and please ensure that you are running on latest Devise and Rails 3.1.


Apologies for the omissions José, I am relatively new to GitHub.

I have spent the past hour or so looking into this, and I have a few more pieces of information.

The application you wanted is here:

Recreating the error should be just a matter of running rake assets:precompile

Indeed, the example will not even permit the initial rake db:migrate.

A few notes:

Adding the Heroku fix config.assets.initialize_on_precompile = false to config/application.rb, does not appear to help.

The problem was apparent in Devise 1.4.5, and upgrading to 1.4.8 has also not helped. The example app uses 1.4.8.

The example app uses Rails 3.1.1, and also displays the known Rack 1.3.4 warning already initialized constant WFKV_, which appears to be unrelated.

My original app is still using Rails 3.1.0 for the moment, but this error seems to occur with both versions.

I have included the same scope code in a similar small application using a simple has_secure_password approach rather than Devise, and it doesn't give the same errors, so it does seem to be something to do with the code Devise adds.

A final note:

I have fixed this in my main app by replacing the scope-with-lambda with a class method, which I believe is now best practice anyway. So I am not under pressure to fix this personally, although it would still be good to know if there is something obvious wrong.

Let me know if there is anything else I can provide, but please bear in mind I am on UK time, so will not respond until tomorrow now.


Ok, thank you very much for the app and the debugging you have done so far. Please keep me posted if you find anything else, I will take a look at your app hopefully later this week.


my recommendation: don't use ":find_by_..." as name for a scope, because scopes always find something. :)
choose a meaningful name like ":by_something" or ":by_skill" (your question on stackoverflow).

if you rename your scope ":find_by_something" in ":by_something", then it works.

hope this helps.


Hi Matt,

Thanks for the tip. I guess I just thought it was functionally equivalent to the generated find_by_... methods, so it ought to be named the same. I suppose it's more similar to a find_by_all_... because it returns an empty array if nothing is found.

Could this actually be causing the error? The lambda function does work, it just causes certain rake tasks to bomb.



Sorry, I can't explain the exact technical cause of the error in your particular case.
This issue can be closed (not a devise issue).

Best, Matt


Okay, cheers Matt.

@ljfc ljfc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.