lib/rails_admin/adapters/mongoid/extension.rb in obitum-rails_admin-0.0.4 vs lib/rails_admin/adapters/mongoid/extension.rb in obitum-rails_admin-0.0.5
- old
+ new
@@ -20,8 +20,29 @@
else
self.send(value)
end
end
end
+
+ module NestedAttributesExtension
+ extend ActiveSupport::Concern
+
+ included do
+ attr_reader :nested_attributes_options
+ alias_method_chain :accepts_nested_attributes_for, :rails_admin
+ end
+
+ # Mongoid accepts_nested_attributes_for does not store options in accessible scope,
+ # so we intercept the call and store it in instance variable which can be accessed from outside
+ def accepts_nested_attributes_for_with_rails_admin(*args)
+ @nested_attributes_options = {}
+ options = args.extract_options!
+ args.each do |arg|
+ @nested_attributes_options[arg.to_sym] = options.reverse_merge(:allow_destroy=>false, :update_only=>false)
+ end
+ args << options
+ accepts_nested_attributes_for_without_rails_admin(*args)
+ end
+ end
end
end
end