0

我有一个接受嵌套模型,并且我已经设置了将值发送到数据库的表单。但不知何故,在将记录存储在数据库中时,activerecord 忽略了名为“deactived_by”的列之一。

这是允许嵌套接受的控制器代码 - 列 deactivated_by 在那里。

# Never trust parameters from the scary internet, only allow the white list through.
def customer_params
  params.require(:customer).permit(:name, :legal_name, :abbr, :fein, :dnb, :customer_status_id, :customer_level_id, :customer_type_id, 
  :creator_id, :update_by, :last_updated_on,
  :customer_owners_attributes => [:id, :employee_id, :active, :customer_id, :**deactivated_by**, :deactivation_reason]
  )
end

在此之后,我将粘贴来自 webrick 日志的代码,该代码显示输入的列值 - 但在随后的数据库记录插入中被忽略。

Parameters: {"utf8"=>"✓", "authenticity_token"=>"Sja4vVHQkU4IZLGGdPQ4Nv8hDwUsZtUVj2f8m3XG6cE=", "customer"=>{"customer_status_id"=>"1", "customer_level_id"=>"3", "name"=>"Ms. Lisa Atkins", "customer_owners_attributes"=>{"0"=>{"id"=>"", "employee_id"=>"3", "customer_id"=>"2970", "active"=>"1", "**deactivated_by**"=>"3", "deactivation_reason"=>""}}, "legal_name"=>"", "fein"=>"", "dnb"=>""}, "commit"=>"Submit", "id"=>"2970"}
  Customer Load (0.4ms)  SELECT `customers`.* FROM `customers` WHERE `customers`.`id` = 2970 LIMIT 1
   (0.2ms)  BEGIN
  CustomerOwner Load (0.4ms)  SELECT `customer_owners`.* FROM `customer_owners` WHERE (customer_id = 2970 and id != NULL)
  SQL (11.9ms)  INSERT INTO `customer_owners` (**`active`, `created_at`, `customer_id`, `deactivation_reason`, `employee_id`, `updated_at`**) VALUES (1, '2013-09-02 02:19:54', 2970, '', 3, '2013-09-02 02:19:54')
   (0.6ms)  COMMIT

怎么会这样?- 为什么 activerecord 忽略这个特定的列?

有任何想法吗?

4

0 回答 0