0
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”类中获取模型名称

谢谢!

4

1 回答 1

3

你可以这样做:

a.klass   #=> Admin
or
a.klass.name #=> "Admin"
于 2013-03-22T11:50:13.790 回答