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

Viewed 13182

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 to write in backend/resourse_helper.rb

module Backend::ResourceHelper

  def attributes
    resource_class.attribute_names - %w(id created_at updated_at)
  end

end

I get the following error:

undefined method `attribute_names' for Backend::User:Class

(I rooted backend to "backend/users#index"). Backend::User inherits from User:

class User
  include Mongoid::Document

  devise_for :users

  field :name
  field :address
end

I just need a list of fields for that User:Class, as I guess (i.e. ["email", "name", "address", ...]), but I broke my head trying to find how.

4 Answers
Related