Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 Rails 应用程序的新手,我让用户输入 3 个不同的整数。如何将存储在数据库中的整数的总和相加并显示总和。假设我有这些整数 :dish1 (3), :dish2 (2), :dish3 (5) 总和应该显示 10?非常感谢任何帮助。
不知道您的表架构,并假设您使用的是 ActiveRecord,这里有一个示例代码。
record = Model.first sum_of_dishes = record.dish1.to_i + record.dish2.to_i + record.dish3.to_i