【发布时间】:2017-10-02 23:08:51
【问题描述】:
我正在通过创建电子商务应用来学习 ruby on rails。
我的问题是,如果客户选择了Pick up in store 或总金额高于$100,我将如何删除delivery cost?
因此,当Pick up in store 或总金额大于$100 时,应删除运费。
我使用if 和else 来获得所需的结果。但是通过使用 Total cost 在选择 radio buttons 时不会更新。
这是没有if和else的代码
<tr>
<th><p>Products Total: </p></th>
<th><p>Delivery Cost: </p></th>
<th><p>Total Cost: </p></th>
</tr>
<tr>
<td><p ><%= @cart.total_price_usd %></p></td>
<td><p ><%= @del_cost_usd %> </p></td>
<td><p ><%= @cart.total_price_usd + @del_cost_usd%></p></td>
</tr>
<div>
<li><%= f.radio_button :pick_up, "1", checked: false, class: 'delivery-options', data: { question: "Pick up items in store" } %>
<%= f.label :pick_up, "Pick up items in store" %></li>
<li><%= f.radio_button :pick_up, "0", checked: true, class: 'delivery-options' , data: { question: "Have items sent by mail" } %>
<%= f.label :pick_up, "Have items sent by mail", class: '' %></li>
</div>
谁能告诉我我想要的结果。
对于有经验的人来说,这可能是容易的点
TIA 码娘
【问题讨论】:
-
有人可能会直接回答。我不能流利地给你一个“我的头顶”的答案,而是查找“使用 JavaScript 隐藏元素”。我在我的一些应用中使用它来达到同样的目的。
标签: ruby-on-rails ruby radio-button e-commerce