私は、ユーザーが配送オプションを選択するページを私のアプリケーション上に持っています。私は彼らの選択肢をデータベースのorder.total
に追加する必要があります。モデルメソッドをsimple_formで呼び出すレールで送信
def update_order_from_shipping_page(shipping)
new_total = self.total + self.shipping
self.update_attributes(total: new_total)
end
そして、私の見解では次の形式::私は、次のカスタムorder.rb
モデル内のメソッド持って
%= simple_form_for @order, url: charges_update_order_path(:shipping), method: :post do |f| %>
<div class="row">
<div class="form-inputs text-left">
<div class="form-group col-sm-6">
<%= f.collection_radio_buttons :shipping, shipping_choices, :first, :last, item_wrapper_class: :block_radio_button_collection %>
</div>
</div> <!-- form inputs -->
</div> <!-- choices row -->
<div class="row">
<%= f.button :submit, "Calculate Shipping" %>
</div>
<% end %>
をそして、私は次のルートに作成している:私は持っている
post 'charges/update_order'
をこれは私のですcharges_controller
:
def update_order
@order = current_order
if @order.update_order_from_shipping_page(shipping)
redirect_to new_charge_path and return
else
redirect_to :back
flash[:notice] = "Something is amuck."
end
end
ラジオボタンが正しくポピュレートされ、コンソールエラーまたはサーバーエラーは表示されませんが、charges#new
ページに表示される合計には、モデルメソッドによってトリガされた更新が反映されません。誰かが私が間違っているのを見ることができますか?
アクションを作成して送信します。 http://stackoverflow.com/a/7507925/4643970 –
@MahmoudSayed、参考にしていただきありがとうございます!私はOPを大幅に更新しましたが、モデルメソッドが有効になっているのを見ていません。 – Liz