How to change the default model template in a Rails scaffold?

If I want to change the default controller template created by scaffold in Rails, it is dead easily - after Googling has discovered around me, I can simply put the controller.rb file in lib / templates / rails / controller so that the generator can pick up instead of the value default.

I cannot find any explanation where I can do the same for the model file. I do not want to create a separate generator, I just want:

> rails generate model foo 

create a model file foo.rb based on the model.rb template that I am doing.

+4
source share
1 answer

Not sure if this is a great idea, but here you can find the generator code: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/model/model_generator.rb

 module Rails module Generators class ModelGenerator < NamedBase #metagenerator argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]" hook_for :orm, :required => true end end end 

According to this post , although you can place the template in lib/templates/rails/model , although you may need to indicate where it is located through the rake task, according to this

+1
source

Source: https://habr.com/ru/post/1400677/


All Articles