How to share custom getter and setter methods across models in Ruby on Rails? -
i have these custom getter , setter methods in of models:
def hourly_rate hourly_rate_in_cents.to_d / 100 if hourly_rate_in_cents end def hourly_rate=(number) self.hourly_rate_in_cents = number.to_d * 100 if number.present? end
is possible share these across models?
if put them , how include them in models need them?
thanks help.
you pull them out separate module, can defined in module directory, e.g. app/modules
then include them in model, e.g. include 'hourly_rate'
Comments
Post a Comment