instance method migration_template

Ruby on Rails 7.1.6

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 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"

Parameters

source req
destination req
config opt = {}
Source
# 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

Defined in railties/lib/rails/generators/migration.rb line 56 · 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