Skip to content

Instantly share code, notes, and snippets.

@chamnap

chamnap/file1

Last active Dec 14, 2015
Embed
What would you like to do?
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