The project I’m working on has about 50 database tables and I have used the default scaffold MVC for each model but I need to reskin them and doing this for all the views and controllers is a pretty unforgiving task.
I knocked up a quick Ruby script that takes a template controller file and can replace template reference to classes and variables and can do the same with edit and new views.
But I thought that there must be a way of overriding the default scaffold builds for views and controllers and so it appears. The official Rails guide isn’t too bad on saying how to override the views, but it took a fair amount of digging around to find where to find the files used by scaffold to copy into lib/templates/erb/scaffold/ for tweaking; I tried the index but the amount of effort required to get that template working is probably greater than manually updating each one.
But I’ve had no such luck with the controller. The Rails guide instructions (and I’m not criticising the author – I’ve had enough people at work do that to me) but it’s very difficult to follow and the instructions given just don’t work. And other blog posts for the same thing don’t work. I find that a lot with Rails tutorials: articles are just repeated verbatim under the blogger’s name or teh stuff just doesn’t work.
You spend so much time trying to figure the correct way of doing things that you end making a mess of the project with 3 or 4 schemes that are difficult to unpick when you finally realise that it’s bogus. I now have a lib/templates directory that contains a couple of bits I know to work, some that might, some that might if they’re put somewhere else and stuff that will never work.
In the end two wasted days and another ‘Rails way’ scheme I’ve put off of.