# Adding classes without script\\generate

**URL:** <https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354>\
**Category:** Rails\
**Created:** [May 1, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354 "2006-05-01T21:48:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 1, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354/1 "2006-05-01T21:48:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 1, 2006, 10:51pm UTC](https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354/2 "2006-05-01T22:51:52Z")

</div>

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 S. 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

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 6:43am UTC](https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354/3 "2006-05-02T06:43:23Z")

</div>

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… 🙂
> 
> > 1. You most probably need a require statement in your controller file.  
> > i.e. require ‘class\_name’

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 1, 2006, 11:02pm UTC](https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354/4 "2006-05-01T23:02:16Z")

</div>

whoops… I meant require ‘file name’… damn my fingers… 🙂

> 1. You most probably need a require statement in your controller file.  
> i.e. require ‘class\_name’

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 3, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354/5 "2006-05-03T18:58:23Z")

</div>

Are you using just regular irb or script/console? You need to use  
script/console or else your class won’t be available.

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/adding-classes-without-script-generate/94354/6 "2006-05-03T18:59:46Z")

</div>

2006/5/2, Pradeep S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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
