Redirecting from routes when the constraints fail
问题 I want to redirect to a different url when the route constraint fails Route.rb match '/u' => 'user#signin', :constraints => BlacklistDomain blacklist_domain.rb class BlacklistDomain BANNED_DOMAINS = ['domain1.com', 'domain2.com'] def matches?(request) if BANNED_DOMAINS.include?(request.host) ## I WANT TO REDIRECT HERE WHEN THE CONDITION FAILS else return true end end end 回答1: Because Rails routes are executed sequentially, you can mimic conditional login in the following manner: # config