How can I get all field names of the Mongoid Document?

前端 未结 4 660
孤街浪徒
孤街浪徒 2021-02-02 13:36

I\'m building backend system, as written in Iain Hecker\'s tutorial: http://iain.nl/backends-in-rails-3-1 and I try to adapt it to MongoDB with Mongoid.

So when I need t

4条回答
  •  时光说笑
    2021-02-02 14:08

    Mongoid already provides you the attributes for an object:

    Model.new.attributes
    

    To get the names for these attributes:

    Model.fields.keys
    

提交回复
热议问题