Created
October 24, 2012 16:27
-
-
Save moreta/3947135 to your computer and use it in GitHub Desktop.
rails redirect
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
#railsでsaveをするときにerrorをcountingしてredirectする。 | |
def save | |
order = Order.new(params[:order]) if order.save | |
redirect_to action: "display" else | |
session[:error_count] ||= 0 session[:error_count] += 1 if session[:error_count] < 4 | |
self.notice = "Please try again" else | |
# Give up -- user is clearly struggling | |
redirect_to("/help/order_entry.html") end | |
end end |
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
# Redirect to referer | |
def save_details | |
unless params[:are_you_sure] == 'Y' | |
redirect_to(:back) | |
else | |
... | |
end | |
end | |
# Redirect permanently | |
headers["Status"] = "301 Moved Permanently" | |
redirect_to("http://my.new.home") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment