views:

16

answers:

3

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

+1  A: 

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 ??

krunal shah
Yeah, this would works, I would only has to put this in to rake script, add method to append comments with output to models.
sparrovv
@sparrow if my answer satisfy your question. please up vote and set it as your answer.
krunal shah
@krunal I would like to vote, cause I Like your answer, but I need 15 reputation to do so. I can't set it as an answer, cause I was looking for plugin
sparrovv
+1  A: 

You're probably thinking of the annotate_models plugin.

zetetic
A: 

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

Chubas