Reputation: 261
I am new to rails app, and I had the users input 3 different integers. How do I add up the sum of the integers stored in the database and show the sum. Assuming I have these integers :dish1 (3), :dish2 (2), :dish3 (5) the sum should show 10? Any help much appreciated.
Upvotes: 0
Views: 636
Reputation: 594
Not knowing your table schema, and assuming you are using ActiveRecord, here is a sample code.
record = Model.first
sum_of_dishes = record.dish1.to_i + record.dish2.to_i + record.dish3.to_i
Upvotes: 1