Rails 3 Routing Constraint and Regex

后端 未结 2 1800
北海茫月
北海茫月 2021-01-07 10:23

I\'m looking to match the pattern state/city in the path, unless the state variable equals \"auth\"

match \'/:state/:city\' => \'cities#index         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 10:34

    Based on mu is too short's comments, here is the answer I've come up with:

    match '/:state/:city' => 'cities#index', :as => :state_cities, :constraints => OmniauthPassThru.new
    

    lib/omniauth_pass_thru.rb

    class OmniauthPassThru
        def initialize
            @passthru = ["/auth/facebook", "/auth/twitter"]
        end
    
        def matches?(request)
            return false if @passthru.include?(request.fullpath)
            true
        end
    end
    

提交回复
热议问题