views:

14

answers:

1

In Rails, if I create a scaffold foo, and do rake db:migrate, then now

app/models/foo.rb

is created. So if I go to

script/console   (or rails console for Rails 3)

and type

$".grep /foo/i

it is empty. $" is the loaded files. So foo.rb is not loaded yet.

Now I do a Foo.all, and foo.rb should be loaded now.

But when I repeat the grep, it is still showing empty array -- why is that?

(On the other hand, I can grep for pp, and it shows nothing, but after I require 'pp', then the grep shows it)

+2  A: 

It's depend which environement you use.

In development time, it's require and load only when you want and reload each time. In production mode, it's only require once and load once. It's load on start of you application. All model on app/models are load.

The configuration to do that is : config.cache_classes = true

shingara
wow, a precise and exact answer within 4 minutes at 4:50am... oh you are in France... have you used Rails for a long time to know such details?
動靜能量
I use rails since 3 years now. You can see my github account : http://github.com/shingara to more information about my code.
shingara