zilla
zilla

Reputation: 952

Rails: Redirecting all routes in a namespace to root

I'm looking to redirect all routes in a Rails namespace to the root path. Here's what I have so far. It works, but I wanted to see if I could get it into a single line:

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

Upvotes: 5

Views: 2826

Answers (1)

Muntasim
Muntasim

Reputation: 6786

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

Upvotes: 8

Related Questions