views:

59

answers:

3

I'm aware that I can check an ActiveRecord through the rails console but it shows the entire output in one line. This can be an issue to look up a specific attribute if the table has many columns.

>> Story
=> Story(id: integer, name: string, link: string, created_at: datetime, updated_at: datetime)

I like how the attributes are displayed in the create migration files but if I have many migration files, it might be a bit hard to track the one that I want.

In Django, I can go straight to the models.py and check the attributes for any models I want. How do Rails developers do this kind of lookup?

+3  A: 

config/schema.rb has the db schema, and in other words all the attributes. I just open the file and search for "posts" for a Post model, and so on.

August Lilleaas
A: 

I normally just describe the table from the database shell.

Omar Qureshi
+2  A: 

Another way to do this is to use the annotate_models plugin/gem. It will add a comment to the top of your model files.

An example (from the README):

  Schema as of Sun Feb 26 21:58:32 CST 2006 (schema version 7)
  #
  #  id                  :integer(11)   not null
  #  quantity            :integer(11)   
  #  product_id          :integer(11)   
  #  unit_price          :float         
  #  order_id            :integer(11)   
  #
Jared