Can I add classes to a rails application manually i.e without using script generate Model/Controller? The reason I am asking, I added a class by putting it in the controller class. I can access the class and its method from command-line (irb), but when I try to instantiate it in another controller, I get "uninitialized constant" error. If I try using script\generate Model ClassName, it adds "< ActiveRecord::Base", where as I need to inherit another class. ClassName < ActiveRecord::Base Thanks, Pradeep -- Posted via http://www.ruby-forum.com/.
Are you using just regular irb or script/console? You need to use script/console or else your class won''t be available. On 5/1/06, Pradeep Sethi <psethi@gmail.com> wrote:> > Can I add classes to a rails application manually i.e without using > script generate Model/Controller? > > The reason I am asking, I added a class by putting it in the controller > class. I can access the class and its method from command-line (irb), > but when I try to instantiate it in another controller, I get > "uninitialized constant" error. > > If I try using script\generate Model ClassName, it adds "< > ActiveRecord::Base", where as I need to inherit another class. > > ClassName < ActiveRecord::Base > > Thanks, > > > Pradeep > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060501/1f486e84/attachment.html
Pradeep, 1) If this class is meant to be a model then it should inherit from ActiveRecord::Base. 2) I hand write classes all the time, there is no need to use the model generator if you don''t want to. 3) You most probably need a require statement in your controller file. i.e. require ''class_name'' 4) If it''s a model, you will have to put a "model :model_name_in_singular_lower_case" in your controller that accesses it 5) You are getting the constant not recognized error since the interpreter can''t resolve your class. I hope this helps and please be advised that I am not an expert in this area. ilan Pradeep Sethi wrote:> Can I add classes to a rails application manually i.e without using > script generate Model/Controller? > > The reason I am asking, I added a class by putting it in the controller > class. I can access the class and its method from command-line (irb), > but when I try to instantiate it in another controller, I get > "uninitialized constant" error. > > If I try using script\generate Model ClassName, it adds "< > ActiveRecord::Base", where as I need to inherit another class. > > ClassName < ActiveRecord::Base > > Thanks, > > > Pradeep-- Posted via http://www.ruby-forum.com/.
whoops.. I meant require ''file name''.. damn my fingers.. :)> 3) You most probably need a require statement in your controller file. > i.e. require ''class_name'' >-- Posted via http://www.ruby-forum.com/.
I figured out the error. I needed to restart my server every time, I make a change to the class file (because it is not a controller and/or Model...) feel like stupi..... :) ilan berci wrote:> whoops.. I meant require ''file name''.. damn my fingers.. :) > >> 3) You most probably need a require statement in your controller file. >> i.e. require ''class_name'' >>-- Posted via http://www.ruby-forum.com/.
Douglas Livingstone
2006-May-02 15:46 UTC
[Rails] Re: Adding classes without script\generate
2006/5/2, Pradeep Sethi <psethi@gmail.com>:> I figured out the error. > > I needed to restart my server every time, I make a change to the class > file (because it is not a controller and/or Model...) > > feel like stupi..... :) >In 1.1, you can add "include Reloadable" in the model so that you don''t have to restart the whole server. Douglas