我有一個要求,我們必須添加兩個文本字段並在第三個存儲爲字符串的值中插入值。 在下面的表格中,我想將數量和price_per_unit相乘,並將值存儲在只能讀取的total_amount字段中。 請幫幫我。如何在第三個文本字段中添加兩個文本字段值的rails形式?
這是我的形式:
<%=form_for([:invoice_detail,@multiple_good], html: {class: 'form-horizontal', role: 'form' }) do |f| %>
<div class="field">
<%= f.label :description_of_goods, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :description_of_goods, :class => 'text_field', :required => true,:maxlength => 20, :placeholder => '20 Alpha numeric characters' %>
</div>
</div>
<div class="field">
<%= f.label :quatity, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :quatity, :class => 'text_field', :required => true,:maxlength => 20, :placeholder => 'Enter quatity' %>
</div>
</div>
<div class="field">
<%= f.label :price_per_unit, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :price_per_unit, :class => 'text_field', :placeholder => 'Enter price Per unit' %>
</div>
</div>
<div class="field">
<%= f.label :total_amount, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :total_amount, :class => 'text_field', :placeholder => 'Enter Total Amount ' %>
</div>
</div>
<div class="form-actions2"style="text-align:center">
<%= f.submit :class => 'btn btn-primary' %>
</div>
</div>
<% end %>
感謝您的回答。其實價格,數量和total_amount,都是數據庫領域。 – venkat 2015-04-01 05:11:32
那麼,你應該明確地在模型中設置這個值,比如'before_save:proc {self.total_amount = price * quantity}'。 – argentum47 2015-04-01 05:19:10
我越來越錯誤,因爲**無法將字符串轉換爲整數** – venkat 2015-04-01 05:28:12