Rails Routes - How to make them case insensitive?

后端 未结 6 477
春和景丽
春和景丽 2021-01-17 18:10

Routes in Ruby on Rails are case sensitive. It seems someone brought this up before, and it has been labeled will not fix.

http://rails.lighthouseapp.com/projects/89

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 18:18

    Though URLs are case-sensitive, if you want to make your routes case-insensitive, there is a dirty hack you can do.

    In application_controller.rb put:

    rescue_from ActionController::RoutingError do |exception|
     redirect_to request.url.downcase
    end
    

    But don't actually do that. You create a redirect loop for any non-existant routes. You really should parse request.request_uri into its components, downcase them, and use them to generate the legit route that you redirect to. As I mentioned right off, this is a dirty hack. However, I think this is better than making your route map ugly and hackish.

提交回复
热议问题