Skip to content

Instantly share code, notes, and snippets.

@mrhead
Created September 27, 2021 08:59
Show Gist options
  • Save mrhead/665f35e967126d56f4af4a94b455b31f to your computer and use it in GitHub Desktop.
Save mrhead/665f35e967126d56f4af4a94b455b31f to your computer and use it in GitHub Desktop.
# 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