ActiveRecord subclassing best practises


#1

Hi,

I want some of my models to inherit from a custom ActiveRecord::Base
class. Where is the best place to put this custom subclass?

Actually, I just wanted to translate the default validate message so
maybe there was a better thing to do than subclassing
ActiveRecord::Base.

Thanks

Oscar


#2

Oscar Picasso wrote:

Hi,

I want some of my models to inherit from a custom ActiveRecord::Base
class. Where is the best place to put this custom subclass?

Actually, I just wanted to translate the default validate message so
maybe there was a better thing to do than subclassing
ActiveRecord::Base.

Oscar,

You can supply a custom message to the validates_* methods.

See:
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html

e.g.

validates_length_of :last_name, :maximum=>30, :message=>“less than %d if
you don’t mind”

A.