Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override the default Rails model template

I want to override the default model file that's generated with rails generate model. I've created a template based on this file, but I can't figure out where to put it. Other answers seem to suggest /lib/templates/rails/model/model.rb or /lib/templates/rails/model/model_generator.rb, but neither of those do anything - I put the template in that location but when I run rails generate model ModelName it gets ignored.

Am I going about this the right way? Where should I put the template?

like image 240
GMA Avatar asked Jan 03 '14 14:01

GMA


2 Answers

Solved: I wanted lib/templates/active_record/model/model.rb.

like image 189
GMA Avatar answered Oct 07 '22 07:10

GMA


You probably need to put it in "lib/rails/generators/active_record/model/templates/model.rb". Here's the rails' default one: https://github.com/rails/rails/blob/master/activerecord/lib/rails/generators/active_record/model/templates/model.rb

like image 38
Cristian Bica Avatar answered Oct 07 '22 08:10

Cristian Bica