Using custom scaffold templates for Rails models and controllers?
After getting tired of rebuilding all my default scaffold models, views and controllers I decided to create custom templates as outlines on various blogs / SA questions etc.
/lib/templates/active_record/model.rb /lib/templates/rails/scaffold_controller/controller.rb /lib/templates/erb/scaffold/_form.html.erb.tt (and so on for the actions etc.)
I added this to my
config.generators do |g| g.orm :active_record g.template_engine :erb g.test_framework :test_unit, fixture: true g.skip_routes true end
I then run the scaffold:
The issues are that the model and controller templates are not used and the views work fine.
I found this post https://stackoverflow.com/questions/23624311/scaffolding-rails4-empty-controller detailing that active admin (which I use) uses
inherited_resources_controller. I am guessing that is part of the issue but I am at a loss how to fix this. I can't seem to find an obvious solution posted anywhere else.
The model template needs to be in:
And the controller template needs to be:
My updated question would be then why is rails using inherited_resources_controller vs scaffold controller and can I fix that?
I stumbled on half of the solution - if I put my controller template in inherited_resources_controller that seems to fix the controller template issue.