Oops ;-p Please forgive the previous, premature send. To restart... ----------------------------------------------------------- I've been working through the "Rolling with Ruby on Rails" tutorial and have come up against something I'm hoping someone here can help me understand. In part one of the tutorial Curt steps the reader through the use of 'generate controller' and 'generate model'. Way cool. In part two, he briefly introduces the new 'generate scaffold' but continues on using what I thought was an equivalent approach that simply required more steps on the programmer's part. That is, I figured 'generate scaffold' was a 'roll up' of existing functionality. Unfortunately, my investigation of 'generate scaffold' leaves me scratching my head. Specifically... The use of "generate controller" results in the creation of a 'recipe_controller.rb' file and a '..\views\recipe' folder. The use of 'generate scaffold' creates 'recipes_controller' and '..\views\recipes'. Class names within the controller are different too. With 'convention' playing such an important role in Ruby and Rails, I've got the feeling that I should understand what's going on here. Can anyone help? Thanks, Bill
on 2006-01-23 17:02
on 2006-01-23 17:09
Bill W. wrote: > With 'convention' playing such an important role in Ruby and Rails, I've > got the feeling that I should understand what's going on here. Can > anyone help? The scaffold generator just pluralises where the controller generator doesn't. That's all there is to it, really. You can override the pluralisation by saying script/generate scaffold ModelName ModelName (that is, repeat the model name precisely). It seems a little inconsistent, but I think I've got my head around the logic behind why it's doing what it's doing. Basically, when you generate a controller on its own, the assumption is that you know what it's for, and it may well not be tied to a specific model. The generator therefore can't assume that it's logical to pluralise the name, because it doesn't know that your controller is going to be used to control bunches of objects. With the scaffolded code, on the other hand, the generator *does* know that the controller is handling more than one object, so /pages/list makes more sense than /page/list. At least, that's how I see it.