Home Simple calculation not working before save, Rails
Reply: 0

Simple calculation not working before save, Rails

user690 Published in May 21, 2018, 10:48 pm

I've got a base_price field, a shipping_price field, and a total_price field.

It's a simple base_price plus shipping_price equals total_price. For some reason, I cannot get this simple calculation to work when saving my model.

Here's my code:


before_save :total_price_calculator


  def total_price_calculator
    self.total_price.to_i = self.base_price.to_i + self.shipping_price.to_i

It's failing to make the calculation and save it in the database and I'm not really getting an error as to why.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.32228 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO