Getting model column names


I am writing a RoR application that connects to a couchDB database using

The definition of my model is the following one:

class BdsDataAuthor < CouchRest::Model::Base
  property :id, Integer
  property :first_name, String
  property :last_name, String

I would like to be able to get the list of the model columns, e.g., the
result of
BdsDataAuthor.columns would be [id, first_name, last_name]

Is it possible? I saw that active_record provides this kind of method
(column_names), but since I am not using active_record...

A solution that I tried is to create a method in the model class (it
works but its not the "best" solution...):

def getColumns
   columns =
   columns << "id"
   columns << "first_name"
   columns << "last_name"

Any idea/suggestion to solve this problem?

Thank you

**columns**(table_name, name = nil) public
Returns an array of Column objects for the table specified by table_name. See the concrete implementation for details on the expected parameter values.

Try this.

Ah sorry, I didn’t see that you aren’t using Active Record…

I haven’t used CouchRest, but a quick skim of this:

seems to indicate that what you’re looking for could be accomplished with:


–Matt Jones

Thanks for your answer.

I will try the properties_with_values method to see if it returns what I

Best regards

Matt Jones wrote in post #1061503:

  property :first_name, String

Any idea/suggestion to solve this problem?

I haven't used CouchRest, but a quick skim of this: