gpt4 book ai didi

ruby-on-rails - rails : Redirecting all routes in a namespace to root

转载 作者:行者123 更新时间:2023-12-04 06:26:06 25 4
gpt4 key购买 nike

我希望将 Rails 命名空间中的所有路由重定向到根路径。这是我到目前为止所拥有的。它有效,但我想看看是否可以将其放入一行:

namespace "old_namespace" do
match "/", :to => redirect("/")
match "*path", :to => redirect("/")
end

最佳答案

rails 3

namespace :old_namespace do
match '(*any)' , to: redirect('/')
end
rails 4
namespace :old_namespace do
match '(*any)' , to: redirect('/'), via: [:get, :post]
end

关于ruby-on-rails - rails : Redirecting all routes in a namespace to root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18211760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com