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 1 commit
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
8 changes: 7 additions & 1 deletion lib/generators/paperclip/paperclip_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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

Choose a reason for hiding this comment

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

Line is too long. [126/80]

end

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

def migration_version
if Rails.version.start_with? '5'

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

"[#{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