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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -