【问题标题】:NULL values in database on create action创建操作时数据库中的 NULL 值
【发布时间】:2014-08-28 03:02:56
【问题描述】:

当我点击提交时,参数和所有数据一起显示,然而,当我保存时,它显示为:

 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

为什么会这样?

【问题讨论】:

    标签: ruby-on-rails-3 activerecord ruby-on-rails-3.2 activemodel


    【解决方案1】:

    答案是:

    def create
    #    @billing = Billing.new(params[:billing])
        @billing = current_user.build_billing(params[:billing])
        @billing.save
    end
    

    【讨论】:

      猜你喜欢
      • 2019-07-31
      • 1970-01-01
      • 2022-12-12
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 2023-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多