开发者

Columns information in Active Record Models [closed]

开发者 https://www.devze.com 2023-01-16 13:13 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

开发者_高级运维 Improve this question

Is there a gem or plugin, that can generate a Comments with columns names above the class definition in Active Record model? I'm pretty sure that I've seen something like this, but can't find it anywhere: Example:

# columns Defs
# name:string
# user_id:integer
# etc.
class Post < ActiveRecord::Base

end

I could as well write something like this, but I don't want to reinvent the wheel.

Thanks


To fetch all the model from app folder.

models = []
Dir.foreach("#{RAILS_ROOT}/app/models") do |model_path|
  if FileTest.directory?(model_path)
    next
  else
    filename = File.basename(model_path, '.rb')
    models << filename.camelize.constantize \
      if ["ActiveRecord::Base"].include?(filename.camelize.constantize.superclass.to_s)\
      && filename.camelize.constantize.table_exists?
  end
end

This will display all the columns with datatype.

for model in models
  puts model
  model.columns_hash.select {|column_name,column_type| puts column_name + ":" + column_type }
end

May be this will help you ??


You're probably thinking of the annotate_models plugin.


There is the annotate_models gem. This is the version I once used, but can't tell if is still mantained.

0

精彩评论

暂无评论...
验证码 换一张
取 消