Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version to migration file if rails5+ #96

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
12 changes: 11 additions & 1 deletion lib/generators/acts_as_follower_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ def self.next_migration_number(dirname)
end

def create_migration_file
migration_template 'migration.rb', 'db/migrate/acts_as_follower_migration.rb'
migration_template 'migration.rb', 'db/migrate/acts_as_follower_migration.rb' , migration_version: migration_version
end

def create_model
template "model.rb", File.join('app/models', "follow.rb")
end

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

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

end
2 changes: 1 addition & 1 deletion lib/generators/templates/migration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ActsAsFollowerMigration < ActiveRecord::Migration
class ActsAsFollowerMigration < ActiveRecord::Migration<%= migration_version %>
def self.up
create_table :follows, force: true do |t|
t.references :followable, polymorphic: true, null: false
Expand Down