2

I want to update attributes of a model:

  def update
    MyModel.update_attributes params[:id], params[:mymodel]
    #.....
  end

But it says undefined method `update_attributes' for #<Class:0x0000000396ecb0>. I wonder, isn't this the same as https://stackoverflow.com/a/840323/1708058

Community
  • 1
  • 1
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205

1 Answers1

8

update_attributes is an instance method of ActiveRecord::Relation, you have to use the class method update:

MyModel.update(params[:id], params[:mymodel])

To use update_attributes you could do:

@my_model = MyModel.find(params[:id])
@my_model.update_attributes(params[:mymodel])
toro2k
  • 19,020
  • 7
  • 64
  • 71