Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.