Created
February 5, 2018 16:55
-
-
Save elchingon/9506f32bd628840429639c544daf15b6 to your computer and use it in GitHub Desktop.
Upgrade Rails 4 to Rails 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
filenames = Dir["app/models/*.rb"] | |
filenames.each do |file_name| | |
next if file_name.include? 'application_record.rb' | |
text = File.read(file_name) | |
new_contents = text.gsub(/< ActiveRecord::Base/, "< ApplicationRecord") | |
if text != new_contents | |
p "changing #{file_name}" | |
# To merely print the contents of the file, use: | |
# puts new_contents | |
File.open(file_name, "w") {|file| file.puts new_contents } | |
end | |
end | |
filenames = Dir["app/controllers/**/*.rb"] | |
filenames.each do |file_name| | |
text = File.read(file_name) | |
new_contents = text.gsub(/before_filter/, "before_action") | |
if text != new_contents | |
p "changing #{file_name}" | |
# To merely print the contents of the file, use: | |
# puts new_contents | |
File.open(file_name, "w") {|file| file.puts new_contents } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment