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

前端 未结 8 1160
执笔经年
执笔经年 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条回答
  •  孤城傲影
    2021-02-03 22:25

    I think using the attr_accessible method in the model class for Foo would achieve what you want, e.g.,:

    class Foo < ActiveRecord::Base
    
      attr_accessible :a, :b, :c
    
      ...
    end
    

    This would allow the setting/updating of only those attributes listed with attr_accessible.

提交回复
热议问题