instance method migration_template

Ruby on Rails 4.1.16

Since v3.0.20

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

migration_template(source, destination, config = {})

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

The migration version, 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"

Parameters

source req
destination req
config opt = {}
Source
# File railties/lib/rails/generators/migration.rb, line 54
      def migration_template(source, destination, config = {})
        source  = File.expand_path(find_in_source_paths(source.to_s))

        set_migration_assigns!(destination)
        context = instance_eval('binding')

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

        create_migration numbered_destination, nil, config do
          ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
        end
      end

Defined in railties/lib/rails/generators/migration.rb line 54 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Rails::Generators::Migration

Type at least 2 characters to search.

↑↓ navigate · open · esc close