|
|
|
|
|
by jabagonuts
4477 days ago
|
|
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 |
|