Skip to content

Commit

Permalink
fix migration generator for AR 5.x (#463)
Browse files Browse the repository at this point in the history
fixes #462, #444 and #466
  • Loading branch information
kirillseva authored and EppO committed Nov 20, 2017
1 parent 8377e70 commit dffb0f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/generators/active_record/rolify_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def inject_role_class
end

def copy_rolify_migration
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb"
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb", migration_version: migration_version
end

private
Expand Down Expand Up @@ -82,6 +82,16 @@ def prompt_missing_user
MSG
end

def rails5?
Rails.version.start_with? '5'
end

def migration_version
if rails5?
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/generators/active_record/templates/migration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration
class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
def change
create_table(:<%= table_name %>) do |t|
t.string :name
Expand Down

0 comments on commit dffb0f6

Please sign in to comment.