Scaffold Look & Feel Adjustments (CSS vs changing scaffo


If the structure of the generated code is good and you have the necessary hooks, you can often get away with changing the look and feel with CSS alone. However the rails scaffold generator has some shortcomings in what it generates (IMHO). So when we were creating a generator for the MasterView project, we started from that but then ended up changing most of it out to use divs and to apply the proper CSS classes to give you the hooks you need. We did use a table for the list partial, because to me it seems really hard to try and do tabular data with divs. Yes it can be done, but it is somewhat painful and seems to be more rigid (having to define column sizes and not allowing the structure to resize with the data like tables do. But I agree with everyone otherwise in that divs are much better for CSS layout in general except for when you actually need a table (then use a table :slight_smile:

The answer to your question about whether you can modify the scaffold templates is: absolutely. This is Ruby :slight_smile: You can modify the templates, however I would suggest just copying the scaffold generator or any other generator that is closest to what you want and then modify it, creating a new generator.

There is a wealth of information on this page about generators and doing just that.


Jeff Barczewski MasterView project founder

If you override a generator would this imply that if there were improvements to the generate in the next version of rails that you would not inherit them? (I’m guessing yes) - would you see this as an issue?

Well it depends on how you overrode things as to whether you would pick up the new features.

But I wasn't necessarily suggesting you override rails scaffold generator (per say) but simply use it as a starting point to create your own just like so many others have done. You end up with a different generator which you can call. The other one is still there and if you ever want to run the other one to compare the differenences you can.

So while it is possible to extend a core generator, for most things it is not really worth the effort especially if the bulk of the changes are in the template itself. Most people who have written generators have simply written their own, many starting with what one of the existing generators does and modified.

If there are signifigant improvements then you can choose to diff the files and move them over into your generator as well. However since the rails team believes in only minimalistic scaffolding, you are probably not going to encounter missing features that often.

thanks for clarifying Jeff