Hi. I''d like to edit the generated template in AR where tables are
created.
for example, this file is created when generating a new model or
migration:
class CreateModel < ActiveRecord::Migration
def self.up
create_table :models do |t|
# t.column :type,
I''d like to edit the above so it''ll generate this:
class CreateModel < ActiveRecord::Migration
def self.up
create_table :models do |t|
# t.column :type, :limit => , :null => false
Can someone point me in the right direction?
I appriciate it.
D
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
To myself. That''s easy: http://rails.techno-weenie.net/question/2006/3/26/change_indentation_of_auto_generated_rails_code D Dominic Son wrote:> Hi. I''d like to edit the generated template in AR where tables are > created. > > for example, this file is created when generating a new model or > migration: > > class CreateModel < ActiveRecord::Migration > def self.up > create_table :models do |t| > # t.column :type, > > I''d like to edit the above so it''ll generate this: > > > class CreateModel < ActiveRecord::Migration > def self.up > create_table :models do |t| > # t.column :type, :limit => , :null => false > > Can someone point me in the right direction? > > I appriciate it. > > D-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hello Dominic> To myself. > > That's easy: > http://rails.techno-weenie.net/question/2006/3/26/change_indentation_of_auto_generated_rails_code > > Dominic Son wrote: > > Hi. I'd like to edit the generated template in AR where tables are > > created. > > > > for example, this file is created when generating a new model or > > migration: > > > > class CreateModel < ActiveRecord::Migration > > def self.up > > create_table :models do |t| > > # t.column :type, > > > > I'd like to edit the above so it'll generate this: > > > > > > class CreateModel < ActiveRecord::Migration > > def self.up > > create_table :models do |t| > > # t.column :type, :limit => , :null => false > > > > Can someone point me in the right direction?Don't modify files in Rails gems directory, it's ugly ! Write your own generator, it is also easy. The template you want to change is rails-xx//lib/rails_generator/generators/components/model/templates/migration.rb so you have to make your own model generator, a slightly modified version : go to your Rails Root app. cd lib mkdir generators cd generators cp -Rv PATH_TO_RAILS/lib/rails_generator/generators/components/model/ . mv model my_model cd my_model mv model_generator my_model_generator (modify templates/migration.rb or any other templates files if you like) So your my_model generator is in RAILS_ROOT/lib/generators and you just have to do a : script/generate my_model Foo that you generated files exactly as you want. Note that if you want your another rails apps to benefit from that generator, put it instead in ~/.rails/generators If you upgrade Rails, it will still work (provided Generator API isn't changed !) -- Jean-François. -- À la renverse. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---