undefined method 'geocoded_by' with rake assets:precompile
I know there have been issues in the past with this error message, but this one seems different. I get this undefined method message when I attempt to run rake assets:precompile for my rails 3.1 app. The full output is:
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
undefined method `geocoded_by' for User(Table doesn't exist):Class
Tasks: TOP => environment
geocoder is in my gemfile. Restarting the app server isn't relevant in this case, so what else is there to do?
Thanks,
- Charlie
Are you using version 1.0.4? This sounds like it could be a problem in 1.0.2 that was fixed.
Thanks for the response! Using 1.0.4, tried pulling it from git, too.
Can you say more about your app? Is there actually a User model which calls geocoded_by? If so have you created a users DB table and run all migrations? Also, you might want to do a search for the Table doesn't exist error message...that's an odd one.
I do have a User model which calls geocoded_by. And, yes I have a users table. It's a fully functioning devise app. The only sign of this error is when I run rake assets:precompile…I'll see if I can track down any more clues.
For any record I am getting this too.
Me too. Anyone come up with a fix?
I can try, for the meantime this should work:
class Location < ActiveRecord::Base
extend Geocoder::Model::ActiveRecord
geocoded_by :address_for_geocode
reverse_geocoded_by :latitude, :longitude
end
That seemed to do the trick! Nice find, and thanks.
+1, same issue here.
+1 Any fix ?
The problem comes from this commit.
With this condition :
if ENV['RAILS_GROUPS'].to_s != 'assets'
As rake assets:precompile is executed with RAILS_GROUPS = assets.
That commit was a fix for issue #123 so I can't just revert it. I don't really understand what the RAILS_GROUPS environment variable is for so I'm not sure what to do. Anyone have an (informed) idea?
Also, there are a bunch of related changes to the assets:precompile task in the newly-released Rails 3.1.1. Has anyone tried with that yet?
I am currently using Rails 3.1.1 and still having the issue.
By default the rake task assets:precompile is executed with these environment variables : RAILS_ENV=production and RAILS_GROUPS=assets.
RAILS_GROUPS=assets makes the rake task load the gems which are in the assets group (in the Gemfile).
assets:precompile use RAILS_GROUPS=assets because it needs saas-rails and coffee-rails (which are in the assets group in the Gemfile) to precompile assets (because of the helpers).
Hope I was clear :)
+1 also having this issue
+1 same issue rails 3.1.1
Me too. Although a variation on the same theme:
undefined method 'reverse_geocoded_by'
:)
@dewski's proposal fixed it for me for now...
class Location < ActiveRecord::Base
extend Geocoder::Model::ActiveRecord
geocoded_by :address_for_geocode
reverse_geocoded_by :latitude, :longitude
end
Could you add the gem to the assets group perhaps?
@Sush: I'm merging your commit (the revert). However, I'm a little confused about how to get this working for folks using Heroku. I think you understand asset precompilation better than I do; do you know what a proper solution to issue #123 would be? What about testing for an actual database connection (ActiveRecord::Base.connected?) before inserting Geocoder into ActiveRecord? (see lib/geocoder/railtie.rb)
The best solution for Heroku users is to set config.assets.initialize_on_precompile = false.
It will force the application to not access the DB or load models when precompiling the assets.
Unfortunately as I don't use Heroku I can't try, but it should work well.
If so you just have to revert the commit (and maybe update the documentation for Heroku users) :)
I just published version 1.0.5, which incorporates Sush's fix for this issue.