Ruby on rails 3 创建操作时数据库中的空值
当我单击提交时,参数与所有数据一起显示,但是,当我保存它时,它显示为:Ruby on rails 3 创建操作时数据库中的空值,ruby-on-rails-3,activerecord,ruby-on-rails-3.2,activemodel,Ruby On Rails 3,Activerecord,Ruby On Rails 3.2,Activemodel,当我单击提交时,参数与所有数据一起显示,但是,当我保存它时,它显示为: 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`, `
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
SQL(1.0ms)插入到'billings'('birth`、'city`、'country`、'created_at`、'gender`、'ictype`、'idno`、'monthly`、'name`、'national`、'phone`、'postcode`、'race`、'reference_id`、'shipping_address`、'state`、'street1`、'title`、'updated_at`、'updated`、'uptime`、'user_id`)值中(NULL,NULL,NULL,'2014-08-28 02:55:19',NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,'2014-08-28 02:55:19',NULL,1)
类计费
为什么会这样?答案是:
def create
# @billing = Billing.new(params[:billing])
@billing = current_user.build_billing(params[:billing])
@billing.save
end