rails / protected_attributes

Protect attributes from mass-assignment in ActiveRecord models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Protected attributes breaks creation by array

wstrinz opened this issue · comments

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

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

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