Possible to create this redirecting route in Rails?
Assuming rails version prior to 3.
You can create a new RedirectController
or tuck a single function away in an existing controller, to do something like the following:
map.js_embed '/j/e',
:controller => :redirect_controller,
:action => :some_function,
:path => "embed"
Then your function would do this:
def some_function
if params[:path]
redirect_to "/javascripts/#{params[:path]}.js"
end
end
or something for that effect.
In Rails 4 and above
get '/stories', to: redirect('/posts')
In case you need a named route, you may want to add an explicit as
parameter:
get '/stories', to: redirect('/posts'), as: :however_you_want_to_name_it
Source: Redirection @ guides.rubyonrails.org
In Rails 3, you can redirect inside the routes.rb file.
match "/posts/github" => redirect("http://github.com/rails.atom")