Rails Routes - How to make them case insensitive?

后端 未结 6 476
春和景丽
春和景丽 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条回答
  •  爱一瞬间的悲伤
    2021-01-17 18:29

    A simple solution is, may be not an elegant way, but yet workable is: Use a before_filter in your application controller like this.

      before_filter :validate_case
    
      def validate_case
        if request.url != request.url.downcase
          redirect_301_permanent_to request.url.downcase
        end
      end
    
      def redirect_301_permanent_to(url)
         redirect_to url, :status=>:moved_permanently 
      end
    

    As i already told that its not an elegant but yet workable, so no down votes please. :P

提交回复
热议问题