gnerkus gnerkus - 2 months ago 13
Ruby Question

What’s does the [5.0] in Rails 5’s ActiveRecord::Migration mean?

A migration I created in a Rails 5 application had

5.0
passed into a method:

class CreateVariableKeys < ActiveRecord::Migration[5.0]
...
end


I would like to know what the
[5.0]
means.

Answer

It is a class method of ActiveRecord::Migration and is defined here.

It allows us to select the version of migrations we wish to use between 4.2 and 5.0. The method throws a:

"Unknown migration version ... "

error if an incompatible version is passed as an argument.

Production ready versions of ActiveRecord don’t have that method so it should go away as soon as Rails 5 goes out of beta.

Comments