Search code examples
ruby-on-railsmigrationhelperhelpermethods

Custom helper methods for Rails 3.2 Migrations


I'm trying to access helper methods inside my migrations. I can't seem to get anything to work when accomplishing something like this:

Migration File:

require File.expand_path('lib/migration_helper')
include MigrationHelper

class NewTable < ActiveRecord::Migration
  def change
    create_table :new_table do |t|
      t.boolean :boolean
      safe_delete_methods
    end
  end
end

Migration helper in /lib directory

#Custom Methods available to Migrations

module MigrationHelper
   def safe_delete_methods
     return 
       t.boolean :deleted, :default => 0, :null => false
       t.integer :deleted_by, :default => 0, :null => false
       t.datetime :deleted_at
   end
end

Thank you for any answers


Solution

  • module MigrationHelper
    
     def safe_delete_methods
    
       t.boolean :deleted, :default => 0, :null => false
       t.integer :deleted_by, :default => 0, :null => false
       t.datetime :deleted_at
    
    
     end
    
    end
    

    cann't use return before the code.