irb(main):019:0> a = Admin.first
=> #<Admin _id: 514b318da61654dd05000002, email: "email@email.com", encrypted_password: "$2a$10$b.cWtfPNgUcCubJRX2vjAO6vEsds9OTGO2tn6Lfz2cBU.mwTYsHw.">
irb(main):020:0> a.class.name
=> "Admin"
irb(main):021:0> a = Admin.all
=> #<Mongoid::Criteria
selector: {}
options: {}
class: Admin
embedded: false>
irb(main):022:0> a.class.name
=> "Mongoid::Criteria"
我如何在“Mongoid :: Criteria”类中获得模型名称?
谢谢!
答案 0 :(得分:3)
你可以这样做:
a.klass #=> Admin
or
a.klass.name #=> "Admin"