Hi, I'm getting a little confused how Rails handles loading models.
I'm on development mode, using Rails 3.1.0.rc1 on ruby 1.8.7
My application models are:
Curso
Legislacao
Usuario
And I have another model that is loaded from a gem Im trying to build:
Cidade
My gem is actually a simple engine:
require 'active_record'
require 'my_gem/app/models/cidade'
module MyGem
class MyGemEngine < Rails::Engine
config.to_prepare do
puts ActiveRecord::Base.descendants
end
end
When I start the server it prints, as expected:
=> Booting Mongrel
=> Rails 3.1.0.rc1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Cidade
=> Debugger enabled
But when I try to login and get redirected to the root page
(Curso#new) it prints:
Cidade
Curso
Legislacao
Started GET "/" for 127.0.0.1 at Sun May 29 19:38:58 -0300 2011
Processing by CursosController#new as HTML
Usuario Load (0.3ms) SELECT `usuarios`.* FROM `usuarios` WHERE
`usuarios`.`id` = 1 LIMIT 1
As you can see, the Usuario class was loaded, but was not added to
ActiveRecord::Base.descendants. Which makes me think that it was
loaded after the to_prepare block.
Shouldnt the to_prepare block be called after all loadings had already
happened?
I cant figure out how to eager load this. I could make it load all
models all the time, but is a great overhead, since Ill be dealing
with lots of models in the future.
Can anyone help me with that ??
Regards,
Everton Moreth
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.