Ruby on Rails: Route a deprecated URL to application's root -


how write rails route in config/routes.rb when need point deprecated url still exists on else's website can't control ('/something/article.jsp?id=1787') root of application?

how below (wrong) attempt need corrected?

get '/something/article.jsp?id=1787' => 'root#index' 

you can specify constraint:

get '/something/article', to: redirect('/'),       :constraints => lambda { |request| request.params[:id] == '1787' } 

this creates 301 "moved permanently" redirect.

if don't want redirect, instead want url trigger root#index action, can substitute to: redirect('/') line to: 'root#index'. however, approach keep old url in address bar.

  • more info on redirects here.
  • more info on constraints here.

hope helps!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -