Rails:如何正确使用redirect_to
Rails: how to use redirect_to properly
我的路线文件中定义了以下路线:
constraints( subdomain: "abc" ) do
get "/action" => "abc#init"
get "/action/:d" => "abc#action"
end
我假设我可以通过这种方式从 init
操作重定向:
redirect_to action_path(d: "12345")
但是服务器无限重定向到 init
操作导致浏览器错误。
如何使用 Rails 路径助手执行重定向?
您需要为路线命名
constraints( subdomain: "abc" ) do
get "/action" => "abc#init", as: :init_action
get "/action/:d" => "abc#action", as: :d_action # something fancier maybe
end
redirect_to d_action_path(d: 'something')
我的路线文件中定义了以下路线:
constraints( subdomain: "abc" ) do
get "/action" => "abc#init"
get "/action/:d" => "abc#action"
end
我假设我可以通过这种方式从 init
操作重定向:
redirect_to action_path(d: "12345")
但是服务器无限重定向到 init
操作导致浏览器错误。
如何使用 Rails 路径助手执行重定向?
您需要为路线命名
constraints( subdomain: "abc" ) do
get "/action" => "abc#init", as: :init_action
get "/action/:d" => "abc#action", as: :d_action # something fancier maybe
end
redirect_to d_action_path(d: 'something')