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 Henry wrote:> Is there a way to stop Rails automatically trying to load models? > > Cheers, > Nicholas-- Posted via http://www.ruby-forum.com/.
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 On 4/21/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote:> By loading, do you mean accessing the model''s class on boot up? > Retrieving database rows? > > Nicholas Henry wrote: > > Is there a way to stop Rails automatically trying to load models? > > > > Cheers, > > Nicholas > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 Fowler''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 Henry 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 > >On 4/21/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote: >> By loading, do you mean accessing the model''s class on boot up? >> Retrieving database rows? >> >> Nicholas Henry wrote: >> > Is there a way to stop Rails automatically trying to load models? >> > >> > Cheers, >> > Nicholas >> >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails_Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
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 Olbrich <devlists-rubyonrails@devlists.com> wrote:> 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 Fowler''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 Henry 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 > > > >On 4/21/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote: > >> By loading, do you mean accessing the model''s class on boot up? > >> Retrieving database rows? > >> > >> Nicholas Henry wrote: > >> > Is there a way to stop Rails automatically trying to load models? > >> > > >> > Cheers, > >> > Nicholas > >> > >> > >> -- > >> Posted via http://www.ruby-forum.com/. > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > _Kevin > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Nicholas Henry 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, > NicholasYou 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 :) -- Posted via http://www.ruby-forum.com/.
Thanks, Alex, unfortunately Rails still trys to require/load even if the Class/Model is already avaliable. On 4/21/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote:> Nicholas Henry 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 :) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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. HTH Trevor -- Trevor Squires http://somethinglearned.com On 21-Apr-06, at 10:51 AM, Nicholas Henry wrote:> Thanks, Alex, unfortunately Rails still trys to require/load even if > the Class/Model is already avaliable. > > On 4/21/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote: >> Nicholas Henry 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 :) >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On 21-apr-2006, at 22:35, Trevor Squires 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