Skip to content

Instantly share code, notes, and snippets.

@elchingon
Created February 5, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elchingon/9506f32bd628840429639c544daf15b6 to your computer and use it in GitHub Desktop.
Save elchingon/9506f32bd628840429639c544daf15b6 to your computer and use it in GitHub Desktop.
Upgrade Rails 4 to Rails 5
#! /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