Class inside module is not recognized by model

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs