4

I am using NetBeans to create my first Ruby on Rails application. Is there a way by which I can view all of the properties of a model? Should I just be looking in the database?

ahsteele
  • 26,243
  • 28
  • 134
  • 248

7 Answers7

6

I just use db/schema.rb - seems to work fine for me.

Andy Gaskell
  • 31,495
  • 6
  • 74
  • 83
5

You can use the annotate gem for this - it will add comments to the top of each model indicating its properties.

Greg Campbell
  • 15,182
  • 3
  • 44
  • 45
4

You could call Model.attributes in Rails' console. This gives a hash with all attributes.

Be careful when using this inside your real code as it always recreates the hash and is therefore pretty expensive.

Koraktor
  • 41,357
  • 10
  • 69
  • 99
4

Just type your model name on the rails console then press Enter.

rails c # start your rails console

User

=> User(id: integer, email: string, password_digest: string...)
etlds
  • 5,810
  • 2
  • 23
  • 30
1

In case anyone is viewing this and is using a newer version of Rails, you can just call Model in the console. (I'm on Rails 3.2.1 and Ruby 1.9.2p290.)

In fact, calling Model.attributes in this case does not work.

Tass
  • 1,628
  • 16
  • 28
0

A nice little tool that I use is from MySQL. It is called MySQL Administrator.

It lets me validate that the db (development/test/production), the tables for the db, and finally the columns(attributes).

Gutzofter
  • 2,003
  • 23
  • 26
0
Model.attributes #=> {'name' => 'foo', 'desc' => 'bar'}

P.S. www.railsbrain.com - use this.