Is there a way to stop Rails automatically trying to load models?
Cheers,
Nicholas
Is there a way to stop Rails automatically trying to load models?
Cheers,
Nicholas
By loading, do you mean accessing the model’s class on boot up?
Retrieving database rows?
Nicholas H. wrote:
Is there a way to stop Rails automatically trying to load models?
Cheers,
Nicholas
Alex,
I want to stop the automatically requiring/loading of models when I am
calling it from a controller e.g.
No such file to load – user.rb
as my actual models are outside of the model directory. (it’s a long
complicated story )
I don’t want rails to do this at all, as I want to have have the
control of doing the require.
Cheers,
Nicholas
I don’t know how to disable it, but you might want to take a look at the
‘Sharing Models between Applications’ recipe in Chad F.'s book.
Most of the methods mentioned either make copies of the model files in
the right place, or tell the OS to look for them elsewhere.
On Friday, April 21, 2006, at 1:20 PM, Nicholas H. wrote:
I don’t want rails to do this at all, as I want to have have the
Is there a way to stop Rails automatically trying to load models?
http://lists.rubyonrails.org/mailman/listinfo/rails
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
_Kevin
Thanks Kevin:
In this case it’s a matter of not sharing models, but having control
of what models are required/loaded.
Cheers,
Nicholas
On 21 Apr 2006 17:33:33 -0000, Kevin O.
Nicholas H. wrote:
Alex,
I want to stop the automatically requiring/loading of models when I am
calling it from a controller e.g.No such file to load – user.rb
as my actual models are outside of the model directory. (it’s a long
complicated story )I don’t want rails to do this at all, as I want to have have the
control of doing the require.Cheers,
Nicholas
You might try requiring the proper file in application.rb.
class ApplicationController < ActionController::Base
reuire ‘path/to/my_models/user’
end
That way class User is loaded and available, without looking the model
directory. The question is, is Rails smart enough to not load a model
if defined?(User)
I’m thinking that have a class of User already should prevent Rails from
loading a file to find it. Totally untested solution but there is a
chance it might work
Thanks, Alex, unfortunately Rails still trys to require/load even if
the Class/Model is already avaliable.
On 21-apr-2006, at 22:35, Trevor S. wrote:
Hi Nicholas,
your statement that rails “still tries to require/load even if the
Class/Model is already available” doesn’t make sense.Rails only auto-loads your models as part of a const_missing hook -
which means that from ruby’s perspective, the constant you are
trying to use doesn’t (yet) exist.You can try this for yourself:
Rails also autoloads the models inferred from the associations. I
guess this is the culprit here.
–
Julian ‘Julik’ Tarkhanov
please send all personal mail to
me at julik.nl
Hi Nicholas,
your statement that rails “still tries to require/load even if the
Class/Model is already available” doesn’t make sense.
Rails only auto-loads your models as part of a const_missing hook -
which means that from ruby’s perspective, the constant you are trying
to use doesn’t (yet) exist.
You can try this for yourself:
in models/wibble.rb
class Wibble
puts “#{self.name} loaded”
end
Then run ./script console and type:
Wibble
it should print out “Wibble loaded”
quit from the console and run ./script/console again, typing this:
class Wibble
end
Wibble
it should not print out “Wibble loaded”
As in, Wibble has already been defined so there’s no need to go
looking for (and load) a wibble.rb file…
You might need to post more complete information to diagnose what’s
actually going on.
Trevor S.
http://somethinglearned.com
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs