inheritance - How to inherit from another Rails migration? -


i have rails migration simple user model:

class users < activerecord::migration   def change     create_table :users |t|       t.string :name, :default => :null       t.float :weight       t.datetime :recorded_at       t.timestamps     end   end end 

i have second table history of user. should have same columns name, obviously. should reference user table.

require_relative '20130718143019_create_history.rb'      class history < users   def change     create_table :history |t|       t.references :user       # ...?     end   end end 

how can use inheritence avoid copying migration configuration?

after leaving keyboard tomatoes fell off eyes , clear how can set up:

class users < activerecord::migration   def change     create_table :users |t|       prepare_columns(t)     end   end    protected    def prepare_columns(t)     t.string :name, :default => :null     t.float :weight     t.datetime :recorded_at     t.timestamps   end  end 

...

require_relative '20130718143019_create_history.rb'      class history < users   def change     create_table :history |t|       t.references :user       prepare_columns(t)     end   end end 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -