Redirection in Rails 4 routes

廉价感情. 提交于 2019-12-05 20:33:23

There is a redirection module (also documented in the guide).

Something like :

get '/m/about', to: redirect('/about')
get '/m/user/:id', to: redirect('/user/%{id}')

Which you can combine with route globbing for a generic solution :

get '/m/*path', to: redirect('/%{path}')

How about just refactor your routes a bit:

Eg: Previous routes.rb

resources :users
# ...

Now, it becomes:

['m', ''].each do |sc|
  scope sc do
    resources :users
    # ...
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!