Search code examples
ruby-on-rails-4money-rails

Rails money-rails: Is it necessary the monetize model definition if using migration?


Im a little bit confused with the documentation of money-rails, they say that if you have an integer column called "price_cents" you just need to add the monetize :price_cents definition in the model, however they also say that you can add the money field in database migration like:

def change
    add_money :products, :price
end

But my doubt is: if I use the migration helper add_money then I need to also add the monetize definition in the model? or is it only necessary when you have an integer column?


Solution

  • Yes, both are necessary. monetize :price_cents creates the facade that allows you to use Product.price = 10.99, and set the price_cents column behind the scenes.