rails / protected_attributes

Protect attributes from mass-assignment in ActiveRecord models.
MIT License
228 stars 92 forks source link

Protected attributes breaks creation by array #49

Closed wstrinz closed 9 years ago

wstrinz commented 9 years ago

It seems protected_attributes is preventing creating multiple records using an array. ie

class Foo < ActiveRecord::Base
  attr_accesssible :bar
end

Foo.new({bar: 'baz'})   # => works
Foo.new([{bar: 'baz'},{bar: 'boo'}])   # => throws an error

The error I get is

undefined method `stringify_keys' for #<Array:0x007faa7d6c76c0>
in gems/protected_attributes-1.0.8/lib/active_record/mass_assignment_security/attribute_assignment.rb:51:in `assign_attributes'

As far as I can tell this method of initializing multiple objects is officially supported in the Rails docs

sgrif commented 9 years ago

Does the same error occur if you call build or create? I don't think we override new at the AR class level

wstrinz commented 9 years ago

You're right, looks like its only happening on new. build and create work fine.