在rails中使用simple_form动态添加用户输入

时间:2018-06-29 20:12:39

标签: ruby-on-rails simple-form

我有一个表格,用户可以在其中输入每月费用...

<%= simple_form_for form do |f| %>
<%= f.input :income, label: "Income" %>
<%= f.input :overtime, label: "Overtime" %>
<%= f.input :bonuses, label: "Bonuses" %>
<%= f.input :commission, label: "Commissions" %>
<%= f.input :other_income, label: "Other Income" %>
       *TOTAL HERE*
<% end %>

我希望能够在其中显示 TOTAL HERE 的字段中添加一个字段,该字段动态地添加用户输入的内容,然后将其保存到数据库中。我玩过String插值,但是没有运气。如果有人对我该怎么做有任何想法,我将不胜感激。

谢谢

1 个答案:

答案 0 :(得分:0)

您可以为文本字段编写一个jQuery keyup事件,将所有值求和并将其分配到总文本字段中作为值。这将解决您的问题。