Joels Random Technical and Social thoughts, in this blog you will find things I think will be useful for myself or others to read about, it could be a recipe or how to solve a technical problem in Java or Ruby.
I am a managing partner at solutionstreet.com, hire me by using our contact us page.

March 10, 2010

rails scaffold getting the column list from existing table

Starting with rails 2, for scaffold generation you are forced to pass the column name and data type of each field you want generated. This is fine for new tables, but if you have a table or have added dozens of columns to a table and want to regenerate, and you are lazy like me, typing this long list of columns is a pain. So this script will generate the input you need to pass the generator.

For example, you have a table called "resellers" and it has a bunch of columns, you could do: