当我点击提交时,参数会显示所有数据,但是,当我保存时,它显示为:
SQL (1.0ms) INSERT INTO `billings` (`birth`, `city`, `country`, `created_at`, `gender`, `ictype`, `idno`, `marital`, `name`, `national`, `phone`, `postcode`, `race`, `reference_id`, `shipping_address`, `state`, `street1`, `title`, `updated_at`, `uptime`, `user_id`) VALUES (NULL, NULL, NULL, '2014-08-28 02:55:19', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, '2014-08-28 02:55:19', NULL, 1)
class Billing < ActiveRecord::Base
# attr_accessible :user_id
attr_accessible :title, :birth, :ictype, :idno, :race, :gender, :national, :street1, :postcode, :city, :state, :marital, :shipping_address
belongs_to :user
end
Class ShoppingCartsController < ApplicationController
def create
@billing = Billing.new(params[:billing])
@billing = current_user.build_billing
@billing.save
end
end
为什么会这样?
答案 0 :(得分:0)
答案是:
def create
# @billing = Billing.new(params[:billing])
@billing = current_user.build_billing(params[:billing])
@billing.save
end