我正在建立一个简单的在线商店进行练习并希望跟踪订单历史记录,目前我正在让用户提交但是发货地址和订单历史记录,稍后我会将订单历史记录升级为隐藏领域。
问题是我无法使用简单的表单向我的数据库提交任何内容。
我的表单如下:
<p class="text-center">
congratulations your order is almost complete, please fill out the form below to place your order or <%= link_to "browse other products.", root_path %>
</p>
<%= simple_form_for @placeorder, html: { multipart: true } do |f| %>
<%= f.error_notification %>
<div class="form-inputs" >
<%= f.input :shipping_address, label: false, placeholder: 'Shipping address', input_html: { class: 'input-lg', required: true } %>
<%= f.input :order_history, label: false, placeholder: 'order_history', input_html: { class: 'input-lg', required: true } %>
</div>
<div class="form-actions">
<%= f.button :submit, "Confirm order" %>
</div>
<% end %>
我的地方订单控制器如下所示:
class PlaceOrdersController < ApplicationController
def new
current_order.order_items.each do |order_item|
@last_item_name = order_item.product.name
end
@placeorder = PlaceOrder.new
@order = current_order.order_items
end
def create
@placeorder = PlaceOrder.create(place_order_params)
p "HELLO #{@placeorder}"
if @placeorder.save
flash[:success] = "You've made your order"
redirect_to root_path
else
flash[:alert] = "Something went wrong, check the form and submit your order again"
render :new
end
end
private
def place_order_params
params.require(:place_order).permit(:shipping_address, :order_history)
end
end
我的routes.rb看起来像这样:
Rails.application.routes.draw do
resources :products
resources :checkout
resources :place_orders
resource :cart, only: [:show]
resources :order_items, only: [:create, :update, :destroy], defaults: { format: 'js' }
root to: "products#index"
devise_for :users, :controllers => { registrations: 'registrations' }
end
我有其他形式工作正常,看起来一样。任何帮助将不胜感激。