Rails: Ignoring non-existant attributes passed to create()

前端 未结 8 1183
执笔经年
执笔经年 2021-02-03 22:12

I have the following Rails model:

class CreateFoo < ActiveRecord::Migration
  def self.up
    create_table :foo do |t|
      t.string :a
      t.string :b
            


        
8条回答
  •  旧时难觅i
    2021-02-03 22:43

    I just had this exact problem upgrading to Rails 3.2, when I set:

    config.active_record.mass_assignment_sanitizer = :strict
    

    It caused some of my create! calls to fail, since fields that were previously ignored are now causing mass assignment errors. I worked around it by faking the fields in the model as follows:

    attr_accessor   :field_to_exclude
    attr_accessible :field_to_exclude
    

提交回复
热议问题