How to redirect (301) when changing routing translation?

I am looking for an easy way to do redirects in my application.

SITUATION:

I have such routes:

http://myapp.com/authors/5-hemingway/books/1-moby-dick 

Routes are translated this way (using gem 'i18n_routing'):

 http://myapp.com/acutores/5-hemingway/libros/1-moby-dick 

Now I have changed the translation of acutores to scriptwriters. A simple step, but I would like to redirect all routes containing the old resource name acutores, instead of routes using "scriptores".

My guess is I should play routes.rb with:

 match "/acutores" => redirect("/scriptores") 

But how to do it effectively for all cases when "acutores" appear? (especially with nested routes)

+3
redirect ruby-on-rails ruby-on-rails-3 routing
source share
1 answer

This redirects /acutores/something to /scriptores/something , but does not work with regular /acutores :

 match "/acutores/*path" => redirect("/scriptores/%{path}") 

They seem to handle both:

 match "/acutores(/*path)" => redirect {|params| "/scriptores/#{params[:path]}"} 

- change

This will save you from all slashes:

 match "/acutores(/*path)" => redirect{ |params| "/scriptores/#{params[:path]}".chomp("/") } 

I'm having trouble redirecting browser caching, so clear the cache after the changes.

+8
source share

All Articles