Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Add migration_version variable to migration generator for rails 5 compatibility #2470

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/generators/paperclip/paperclip_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def self.source_root
end

def generate_migration
migration_template "paperclip_migration.rb.erb", "db/migrate/#{migration_file_name}"
migration_template("paperclip_migration.rb.erb",
"db/migrate/#{migration_file_name}",
migration_version: migration_version)
end

def migration_name
Expand All @@ -27,4 +29,10 @@ def migration_file_name
def migration_class_name
migration_name.camelize
end

def migration_version
if Rails.version.start_with? "5"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SUG] Let's do it compatible with higher versions:

if Rails.version.to_i >= 5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked perfectly.

"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class <%= migration_class_name %> < ActiveRecord::Migration
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
def self.up
change_table :<%= table_name %> do |t|
<% attachment_names.each do |attachment| -%>
Expand Down