Skip to content

Commit

Permalink
Add ability to save simple mongoid objects (keys hardcoded to :_id).
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Seritan authored and mshibuya committed Feb 29, 2012
1 parent e604e42 commit dbcd35d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions 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

7 changes: 6 additions & 1 deletion 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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dbcd35d

Please sign in to comment.