1

I have a simple mongodb collection which stores tweets directly from the twitter api (via a ruby script).

I'm now building a simple Sinatra app to display some of these tweets.

So far, I've managed to get a simple view to display some of the tweet data by building a simple Tweet model and assigning variables to some of the fields stored in my tweet collection.

e.g.

class Tweet 
 include Mongoid::Document
 field :text, :type => String
 field :id_str, :type => String
 field :user, :type => String
end

Do I need to create explicit variables for each field in my mongo collection or is there a smarter way of automatically assigning variable names based on the field name stored in mongo?

Thanks,

Ed

nicholaides
  • 19,211
  • 12
  • 66
  • 82
Colm Troy
  • 1,947
  • 3
  • 22
  • 35

1 Answers1

2

Yes, this is called "Dynamic Fields". The Mongoid documentation describes it here: http://mongoid.org/docs/documents/dynamic.html

nicholaides
  • 19,211
  • 12
  • 66
  • 82