Topic: Change the markup generated by scaffold_resource

I'm loving the new scaffold_resource generator, but I don't prefer the markup it generates. How would I override the markup template with my own?

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?

Re: Change the markup generated by scaffold_resource

Instead of overriding the built-in generator, you can duplicate it and create your own. You can find the built in one at vendor/rails/railties/lib/rails_generator/generators/components/scaffold_resource.

There are several places Rails will look for generators. Run script/generate without any arguments for instructions.

Railscasts - Free Ruby on Rails Screencasts

Re: Change the markup generated by scaffold_resource

ryanb wrote:

Instead of overriding the built-in generator, you can duplicate it and create your own. You can find the built in one at vendor/rails/railties/lib/rails_generator/generators/components/scaffold_resource.

There are several places Rails will look for generators. Run script/generate without any arguments for instructions.

I think that creating a whole new generator would be a little excessive for what I'm trying to accomplish. The only thing I want to change in the markup is the form elements. I prefer using an ordered list with list items for the input fields (whereas the default generator just encloses the form inputs in p tags). I found the view_edit.rhtml and view_new.rhtml under the vendor/rails/.../scaffold_resource generator directory. I only needed to change a couple of lines in the those files to get the desired effect. Unfortunately, as soon as I freeze to the latest edge again, those changes will be wiped out. What would be a clever way to be able to make these small changes to the templates without wiping them out every time I freeze again?

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?

Re: Change the markup generated by scaffold_resource

jed.hurt wrote:

Unfortunately, as soon as I freeze to the latest edge again, those changes will be wiped out. What would be a clever way to be able to make these small changes to the templates without wiping them out every time I freeze again?

That's why I had suggested duplicating it. You may find further customizations you want to make as well later on.

However, instead of freeze edge rails, checkout the source using SVN directly. Then you can just run svn update. As long as the same file isn't changed, it should keep your changes without any conflict. There's a sitepoint blog post suggesting how to checkout edge rails this way. I can look for it if you need me to.

Railscasts - Free Ruby on Rails Screencasts