# Class inside module is not recognized by model

**URL:** <https://www.ruby-forum.com/t/class-inside-module-is-not-recognized-by-model/74283>\
**Category:** Rails\
**Created:** [November 3, 2006, 11:11am UTC](https://www.ruby-forum.com/t/class-inside-module-is-not-recognized-by-model/74283 "2006-11-03T11:11:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rinda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@rinda](https://www.ruby-forum.com/u/rinda)\
**Post date:** [November 3, 2006, 11:11am UTC](https://www.ruby-forum.com/t/class-inside-module-is-not-recognized-by-model/74283/1 "2006-11-03T11:11:07Z")

</div>

I have this model:  
class ThermoDetectorOrderLetter \< ActiveRecord::Base  
include ElementValidation  
validates\_presence\_of :sales\_name, :item\_code, :design\_type  
protected

def validate

```
radio_button_with_single_text_field_validated(errors, 

```

calibration\_code\_of\_thermocouple, :calibration\_code\_of\_thermocouple)

```
order_status_validated(errors, order_status, :order_status)

```

…

Other model have similar attributes:  
class TubularHeaterOrderLetter \< ActiveRecord::Base  
include ElementValidation  
validates\_presence\_of :sales\_name, :item\_code, :design\_type  
protected

def validate

```
radio_button_with_single_text_field_validated(errors, 

```

calibration\_code\_of\_thermocouple, :calibration\_code\_of\_thermocouple)

```
order_status_validated(errors, order_status, :order_status)

```

…

This is ElementValidation file that is included by that two models.  
module ElementValidation

class CommonValidation \< ActiveRecord::Base  
def CommonValidation.common\_validation  
validates\_presence\_of :sales\_name  
end  
end

def order\_status\_validated(errors, order\_status, order\_status\_symbol)  
…  
end  
…

It works fine… However I try to remove validates\_presences\_of: line  
from two model with this:  
class ThermoDetectorOrderLetter \< ActiveRecord::Base  
include ElementValidation  
…  
def validate

```
CommonValidation.common_validation

radio_button_with_single_text_field_validated(errors, 

```

calibration\_code\_of\_thermocouple, :calibration\_code\_of\_thermocouple)  
…

But it said: uninitialized constant CommonValidation

Why is it not recognized? order\_status\_validated function that reside in  
Module ElementValidation is recognized by model.

Thank you.

---

<div class="post-metadata">

**Author:** ![rinda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@rinda](https://www.ruby-forum.com/u/rinda)\
**Post date:** [November 4, 2006, 8:04am UTC](https://www.ruby-forum.com/t/class-inside-module-is-not-recognized-by-model/74283/2 "2006-11-04T08:04:08Z")

</div>

Akbar H. wrote:

> I have this model:  
> class ThermoDetectorOrderLetter \< ActiveRecord::Base  
> include ElementValidation  
> end

You should be able to simply use:  
ElementValidation::CommonValidation.common\_validation

But I think inheritance would be better suited for you here rather than  
inclusion.

Something like:

class Element \< ActiveRecod::Base  
self.abstract\_class = true # prevents rails from look for  
# table “elements” on inherited  
# classes.  
validates\_presence\_of :sales\_name

```
def order_status_validated(errors, order_status, 

```

order\_status\_symbol)  
…  
end  
end

class OscillatingEtherealIonizer \< Element  
#already has all default behaviors from Element class  
end
