Skip to content
Browse files

Add ability to save simple mongoid objects (keys hardcoded to :_id).

  • Loading branch information...
1 parent e604e42 commit dbcd35d84b8e3b77f25d0ca5e1b76749929b8a5e Marius Seritan committed with Jan 31, 2011
Showing with 17 additions and 1 deletion.
  1. +11 −0 lib/rails_admin/adapters/abstract_object_mongoid.rb
  2. +6 −1 lib/rails_admin/adapters/mongoid.rb
View
11 lib/rails_admin/adapters/abstract_object_mongoid.rb
@@ -0,0 +1,11 @@
+require 'rails_admin/abstract_object'
+module RailsAdmin
+ module Adapters
+ class AbstractObjectMongoid < RailsAdmin::AbstractObject
+ def attributes=(attributes)
+ object.send :attributes=, attributes
+ end
+ end
+ end
+end
+
View
7 lib/rails_admin/adapters/mongoid.rb
@@ -1,6 +1,7 @@
require 'mongoid'
require 'rails_admin/config/sections/list'
require 'rails_admin/abstract_object'
+require 'rails_admin/adapters/abstract_object_mongoid'
module RailsAdmin
module Adapters
@@ -18,7 +19,7 @@ def self.can_handle_model(model)
def get(id)
if object = model.where(:_id=>BSON::ObjectId(id)).first
- RailsAdmin::AbstractObject.new object
+ RailsAdmin::Adapters::AbstractObjectMongoid.new object
else
nil
end
@@ -28,6 +29,10 @@ def get_bulk(ids)
model.find(ids)
end
+ def keys
+ [:_id]
+ end
+
def count(options = {})
model.count(options.reject{|key, value| [:sort, :sort_reverse].include?(key)})
end

0 comments on commit dbcd35d

Please sign in to comment.
Something went wrong with that request. Please try again.