Question

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)

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top