Skip to content

Instantly share code, notes, and snippets.

@chamnap
Last active December 14, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamnap/5024664 to your computer and use it in GitHub Desktop.
Save chamnap/5024664 to your computer and use it in GitHub Desktop.
Mongoid collection name
require 'mongoid'
class A
end
class B
end
class Book
include Mongoid::Document
end
a_book = A.const_set(:Book, Class.new(Book))
a_book.store_in collection: 'a_books'
b_book = B.const_set(:Book, Class.new(Book))
b_book.store_in collection: 'b_books'
A::Book.collection_name #:b_books, it should return :a_books, right?
B::Book.collection_name #:b_books
require 'mongoid'
class A
end
class B
end
class Book
include Mongoid::Document
end
a_book = A.const_set(:Book, Class.new(Book))
a_book.store_in collection: 'a_books'
A::Book.collection_name #:a_books, need to call this method after set.
b_book = B.const_set(:Book, Class.new(Book))
b_book.store_in collection: 'b_books'
B::Book.collection_name #:b_books, need to call this method after set.
A::Book.collection_name #:a_books, then it displays correctly.
B::Book.collection_name #:b_books, the same here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment