Method: Rails::Generators::Migration#migration_template

Defined in:
railties/lib/rails/generators/migration.rb

#migration_template(source, destination, config = {}) ⇒ Object

Creates a migration template at the given destination. The difference to the default template method is that the migration number is prepended to the destination file name.

The migration number, migration file name, migration class name are available as instance variables in the template to be rendered.

migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'railties/lib/rails/generators/migration.rb', line 56

def migration_template(source, destination, config = {})
  source = File.expand_path(find_in_source_paths(source.to_s))

  set_migration_assigns!(destination)

  dir, base = File.split(destination)
  numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))

  file = create_migration numbered_destination, nil, config do
    ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(binding)
  end
  Rails::Generators.add_generated_file(file)
end