开发者

How do I list out the column names and field types of an existing table in ruby on rails?

Assume: The app name is "demo2" The model was made off of a scaffold generation ("post")

Extra specifics in regards to which sub-folder I need to change to on the com开发者_StackOverflow中文版mand line would be helpful.

Thanks!


You can do: Post.columns and then iterate on the resulting Array.

See more methods at Class: ActiveRecord::Base


Post.columns.each do |column|
  puts "name: #{column.name}, type: #{column.type}"
end


in rails 4 its:

Post.column_names # => ["id", "title", ... ]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜