I have 2 or more models that have a method in common called CapitalizeEachWord.
Can I access the class ActiveRecord::Base and paste the method inside? or create a model called Application that inherits the ActiveRecord::Base directly and then to do that BreakPoint and BusCompany inherit from it?
class BreakPoint < ActiveRecord::Base
attr_accessible :city,:province_id,:province
belongs_to :province
before_save :capitalizeEachWord
validates :city, presence: true,
uniqueness: true,
format: /^([[:alpha:]]+\s?){1,}$/
def capitalizeEachWord
self.city=self.city.downcase.split.map(&:capitalize).join(' ')
end
end
class BusCompany < ActiveRecord::Base
attr_accessible :company
has_many :bus_set_types
validates :company, presence: true,
uniqueness: true,
format: /^([[:alpha:]]+\s?){1,}$/
def capitalizeEachWord
self.name=self.name.downcase.split.map(&:capitalize).join(' ')
end
end