我的应用程序在一个小时前工作得很好,然后我添加了两列,:pick_up
和:send
到'订单'表,之后我得到了这个错误
wrong number of arguments (1 for 0)
我不明白为什么会导致这个错误。
orders_controller.rb:
class OrdersController < ApplicationController
include CurrentCart
before_action :set_cart, only: [:new, :create]
before_action :set_order, only: [:show, :edit, :destroy]
def index
@orders = Order.all?
end
def new
@images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"]
@random_no = rand(5)
@random_image = @images[@random_no]
if @cart.product_items.empty?
redirect_to root_url, notice: 'Your Cart is Empty'
return
end
@order = Order.new
@client_token = Braintree::ClientToken.generate
end
def create
@order = Order.new(order_params)
if @order.save
charge
if @result.success?
@order.add_product_items_from_cart(@cart)
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
OrderNotifier.received(@order).deliver
redirect_to root_url, notice: 'Thank You for Your Order'
else
flash[:error] = 'Please Check Your Cart'
redirect_to root_url, alert: @result.message
@order.destroy
end
else
@client_token = Braintree::ClientToken.generate
render :new
end
end
def show
end
def destroy
@order.destroy
redirect_to root_url, notice: 'Order deleted'
end
private
def set_order
@order = Order.find(params[:id])
end
def order_params
params.require(:order).permit(:name, :email, :address, :city, :country, :pick_up, :send)
end
def charge
@result = Braintree::Transaction.sale(
amount: @cart.total_price_usd,
payment_method_nonce: params[:payment_method_nonce] )
end
end
这是_form.html。订单动词:
<%= form_for @order do |f| %>
<%= render 'msg' %>
<div class="container">
<div class="col-md-10">
<h3>Please Enter Your Details</h3>
</div>
<div class="form-group">
<div class="col-md-10">
<%= f.label :name %>
<%= f.text_field :name, size: 40, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<%= f.label :email%>
<%= f.email_field :email, size: 40, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<%= f.label :address %>
<%= f.text_area :address, cols: 40, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<%= f.label :city %>
<%= f.text_field :city, size: 40, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-5">
<%= f.label :country %>
<%= f.country_select :country, { priority_countries: [ "IS", "US", "DE", "ES", "PT" ]}, { class: "form-control" }%>
</div>
</div>
<div class="form-group">
<div id="payment-form"></div>
<div class="col-md-10">
<br>
<%= f.submit 'Place Order', class: 'buttons' %>
</div>
</div>
</div>
<% end %>
schema.rb的顺序部分:
create_table "orders", force: :cascade do |t|
t.string "name"
t.string "email"
t.text "address"
t.string "city"
t.string "country"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "shipped", default: false
t.string "pick_up"
t.string "send"
end
我担心send
不是一个幸运的标识符名称,因为send
方法。
http://ruby-doc.org/core-2.3.1/Object.html method-i-send