Created
September 27, 2021 08:59
-
-
Save mrhead/665f35e967126d56f4af4a94b455b31f to your computer and use it in GitHub Desktop.
This file contains 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
# Add "status: :see_other" to redirects without explicit redirect status | |
# | |
# This is useful for migration to Turbo: https://turbo.hotwired.dev/handbook/drive#redirecting-after-a-form-submission | |
# | |
# Usage: | |
# | |
# ack redirect_to app/controllers | cut -f 1 -d : | sort -u | while read FILE; do ruby set_redirect_status.rb $FILE; done | |
unless filename = ARGV[0] | |
puts "Filename is required" | |
exit(-1) | |
end | |
new_content = "" | |
File.readlines(filename).each do |line| | |
if line.include?("redirect_to") && !line.include?("status:") | |
new_content << line.chomp + ", status: :see_other\n" | |
else | |
new_content << line | |
end | |
end | |
File.write(filename, new_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment