Skip to content

Commit dffb0f6

Browse files
kirillsevaEppO
authored andcommitted
fix migration generator for AR 5.x (#463)
fixes #462, #444 and #466
1 parent 8377e70 commit dffb0f6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/generators/active_record/rolify_generator.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def inject_role_class
3535
end
3636

3737
def copy_rolify_migration
38-
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb"
38+
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb", migration_version: migration_version
3939
end
4040

4141
private
@@ -82,6 +82,16 @@ def prompt_missing_user
8282
MSG
8383
end
8484

85+
def rails5?
86+
Rails.version.start_with? '5'
87+
end
88+
89+
def migration_version
90+
if rails5?
91+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
92+
end
93+
end
94+
8595
end
8696
end
8797
end

lib/generators/active_record/templates/migration.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration
1+
class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
22
def change
33
create_table(:<%= table_name %>) do |t|
44
t.string :name

0 commit comments

Comments
 (0)