Rails scaffolding
Posted by tom February 17th, 2006
After some investigation I found out that the scaffolding with Rails is all around plurals and singulars. The scaffold option for ruby script/generate is used to taking a singular form. Your database tables need to be in plural form however…
Let’s take the “cookbook” example used in the tutorials. Your tables there should be named “categories” and “recipes”, the tutorial from Curt Hibbs drags you into a recipe MVC, which is not the Ruby way ™.
So to quickly generate code (and save you a lot of typing) this is the way to go as I see it:rails cookbook cd cookbookNow setup your database in config/database.yml
ruby script/generate scaffold recipe ruby script/generate scaffold categoryAfter this, I like this in particular, you’ll end up with a category and recipe model, but with categorIES and recipeS controllers and views. So basically rails/ruby even “understands” the category -> categories!
Also take a look at ActionController::Scaffolding::ClassMethods

Leave a Reply