-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
https://github.com/mongoid/mongoid/issues/1206
I've done required changes for scoped mass assignment.
in lib/mongoid/attributes/processing.rb I inserted a line
attrs = (role == :default ? sanitize_for_mass_assignment(attrs) : sanitize_for_mass_assignment(attrs, role))
It is rather ugly, but it is the most simple way to support both ActiveModel 3.0 and 3.1.
Also, I'made changes to Document#initialize, write_attributes method and added a assign_attributes method according to documentation here: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-i-assign_attributes
my working code:
class Item
field :title, :type => String
field :is_rss, :type => Boolean, :default => false
attr_accessible :title, :as => [:default, :parser]
attr_accessible :is_rss, :as => :parser
end
pry(main)> t = Item.new({ :title => "asdfasdf", :is_rss => true })
WARNING: Can't mass-assign protected attributes: is_rss
pry(main)> t.is_rss
=> false
pry(main)> t = Item.new({ :title => "asdfasdf", :is_rss => true }, :as => :parser)
pry(main)> t.is_rss
=> true