wildabeast
wildabeast

Reputation: 1832

How to redirect a nested resource in routes.rb in Rails 3

I want to redirect http://mysite.com/docs/some-old-link to http://mysite.com/docs/some-new-link (some-old-link is gone). Here's what I'm trying:

resources :docs, :only => [:index, :show] do
  member do
    match "some-old-link"   => redirect("some-new-link")
  end
end

But the redirect isn't happening and I just get 404 on some-old-link. Tried various tweaks on this but can't get it. How do I do this?

Upvotes: 1

Views: 1266

Answers (1)

Tala
Tala

Reputation: 8928

First, try to add "to" to your code:

match "some-old-link",  to: redirect("some-new-link")

The problem also could be:

 member do
    match "some-old-link"   => redirect("some-new-link")
  end

Is expected to redirect sth like this:

/docs/id/some-old-link to /docs/id/some-new-link

try using collection instead of member

Upvotes: 4

Related Questions