geocoder icon indicating copy to clipboard operation
geocoder copied to clipboard

undefined method 'geocoded_by' with rake assets:precompile

Open cmezak opened this issue 15 years ago • 22 comments

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

cmezak avatar Sep 21 '11 19:09 cmezak

Are you using version 1.0.4? This sounds like it could be a problem in 1.0.2 that was fixed.

alexreisner avatar Sep 21 '11 19:09 alexreisner

Thanks for the response! Using 1.0.4, tried pulling it from git, too.

cmezak avatar Sep 21 '11 20:09 cmezak

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.

alexreisner avatar Sep 27 '11 02:09 alexreisner

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.

cmezak avatar Sep 27 '11 14:09 cmezak

For any record I am getting this too.

dewski avatar Oct 04 '11 18:10 dewski

Me too. Anyone come up with a fix?

ghost avatar Oct 04 '11 19:10 ghost

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

dewski avatar Oct 04 '11 19:10 dewski

That seemed to do the trick! Nice find, and thanks.

ghost avatar Oct 04 '11 19:10 ghost

+1, same issue here.

sush avatar Oct 10 '11 10:10 sush

+1 Any fix ?

invaino avatar Oct 11 '11 08:10 invaino

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.

sush avatar Oct 11 '11 10:10 sush

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?

alexreisner avatar Oct 12 '11 15:10 alexreisner

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?

alexreisner avatar Oct 12 '11 15:10 alexreisner

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 :)

sush avatar Oct 12 '11 16:10 sush

+1 also having this issue

rudf0rd avatar Oct 15 '11 03:10 rudf0rd

+1 same issue rails 3.1.1

marbemac avatar Oct 20 '11 16:10 marbemac

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?

morgz avatar Oct 21 '11 16:10 morgz

@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)

alexreisner avatar Oct 22 '11 02:10 alexreisner

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) :)

sush avatar Oct 22 '11 12:10 sush

I just published version 1.0.5, which incorporates Sush's fix for this issue.

alexreisner avatar Oct 26 '11 20:10 alexreisner