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

前端 未结 8 1367
执笔经年
执笔经年 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 use this frequently (simplified):

    params.select!{|x| Model.attribute_names.index(x)}
    Model.update_attributes(params)
    

提交回复
热议问题