You’re not receiving notifications from this thread.
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/erb/scaffold/_form.html.erb.tt (and so on for the actions etc.)
I added this to my
config.generators do |g|
g.test_framework :test_unit, fixture: true
I then run the scaffold:
rails g scaffold MyModel name description notes:text flag_active:boolean slug company_id:integer
Running via Spring preloader in process 52960
route resources :my_models
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?