-1

I want to create a model named "Donations", which has an attribute named "amount" which will be utilizing money-rails gem. Please guide me how to initiate the process. Will it be generated similarly, just need to add "monetize" in that model? Would be helpful if some pro could elaborate its working.

Fuaad
  • 197
  • 15

1 Answers1

1

You can create a model in a similar way we create other models, inside the model use the monetize macro to set the attribute as a Money object.

make sure the column you want to use as a Money object must be postfix by _cents. This will add the amount attribute to each Donation object which is Money object

class Donation
  monetize :amount_cents 
end

If you want to use any other column like column name without _cents as postfix, you have to provide as argument with a string value, make sure column name and string value passed to as argument must be different.

class Donation
  monetize :amount, as: 'contribution'
end

Read this ActiveRecord section of readme to understand it.