Live data from Hacker News

Visualizing Rails Schemas with the RailRoady Gem

engineering.coachup.com

1–10 of 14 posts

Re: Visualizing Rails Schemas with the RailRoady Gem

#6

I prefer rails-ERD. annotate_models is also great.

Instead of annotate models, I have a function in my .irbrc/.pryrc that will print out the columns for me when I'm in a rails console (I usually have one open almost all of the time). I prefer this to cluttering my model files.

  [6] pry(main)> c Account
  Columns for 'accounts'
    id                              :integer
    created_at                      :datetime
    updated_at                      :datetime
    address                         :string
    city                            :string
    state                           :string
    zip                             :string
    phone_number                    :string
    last_ip                         :string

  # Print formatted column names and type info for ActiveRecord models
  def fields(model)
    puts "Columns for '#{model.table_name}'"
    width = model.columns.inject(0) { |max_width, col| col.name.size > max_width ? col.name.size : max_width }
    _columns = model.columns.collect do |c|
      "  %-#{width + 2}s :%s" % [c.name, c.type]
    end.join("\n")
    puts _columns
  end
alias :c :fields

Re: Visualizing Rails Schemas with the RailRoady Gem

#10

I prefer rails-ERD. annotate_models is also great.

Instead of annotate models, I have a function in my .irbrc/.pryrc that will print out the columns for me when I'm in a rails console (I usually have one open almost all of the time). I prefer this to cluttering my model files. [6] pry(main)> c Account Columns for 'accounts' id :integer created_at :datetime updated_at :datetime address :string city :string state :string zip :string phone_number :string last_ip :string…

Do you keep the rails console running constantly? It seems more inconvenient to start and stop the rails console than navigate files for your schema, which is also searchable by virtue of it being written down.
Post reply on HN