Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

The tire:import:all Rake task throws an error: uninitialized constant Addres #744

Closed
congshuanglong opened this issue Jun 1, 2013 · 4 comments

Comments

@congshuanglong
Copy link

I create a model called Address.When I execute a rake task called tire:import:all,an error, uninitialized constant Addres, is throwed.
I notice some code in the source code file,the path of which is lib/tire/task.rb, should be modified to fix the above problem.
the former:
klass = model_filename.classify.constantize
updated to:
klass = model_filename.camelize.constantize

@karmi karmi closed this as completed in 495a6c0 Jun 3, 2013
@karmi
Copy link
Owner

karmi commented Jun 3, 2013

Thanks for the fix!, added and pushed. (See also #733)

@felixbuenemann
Copy link
Contributor

@karmi unfortunately that didn't fix it for me, I had to modify the rake task to depend on the environment and remove require path to get it to work, otherwise it failed to load the models, because one model depended on code from app/uploaders.

@karmi
Copy link
Owner

karmi commented Aug 12, 2013

@felixbuenemann So rake environment tire:import:all fails for you but when you manually change the task to depend on the environment task, it works? Also, rake environment should definitely load all files registered in config.load_paths?

@felixbuenemann
Copy link
Contributor

@karmi rake environment tire:import:all works if I comment require pathinside task.rb, because that line causes the models to be loaded twice causing issues with overwriting scopes, redefining constants and in this case raising an exception on an embedded enum class.

The same happens if I enter the rails console and do a require "./app/models/somemodel".

Maybe this could be fixed by trying to avoid double require like this?

begin
  klass = model_filename.camelize.constantize
rescue NameError
  require(path) ? retry : raise
end

If you think this is a viable solution I could make a PR.

felixbuenemann added a commit to felixbuenemann/tire that referenced this issue Sep 18, 2013
When loading environment berfor tire:import:all, it is possible that
models are already loaded when tire tries to load them. This can cause
redefinition of constants and all other kind of havoc.

This fix first tries to constantize the models to see if they are
already loaded before trying to require them.

See issue karmi#744 for discussion.
karmi pushed a commit that referenced this issue Oct 2, 2013
When loading environment berfor tire:import:all, it is possible that
models are already loaded when tire tries to load them. This can cause
redefinition of constants and all other kind of havoc.

This fix first tries to constantize the models to see if they are
already loaded before trying to require them.

See issue #744 for discussion.

Closes #869
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants