Reputation: 8202
If I want to change the default controller template created by scaffold in Rails it's dead easy - after Googling around I found I can just put a controller.rb file in lib/templates/rails/controller for the generator to pick up on instead of the default.
I cannot find any explanation of where I can do the same for a model file. I don't want to build a separate generator, I just want:
> rails generate model foo
to create foo.rb model file based on a model.rb template I make.
Upvotes: 4
Views: 2053
Reputation: 7111
Not sure if this is a great idea but you can find the generator code here: 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 though you should be able to put a template in lib/templates/rails/model
though you may need to specify where it is located via a rake task according to this
Upvotes: 2