Rails 路由错误

Rails Route Bug

我正在为我需要的方法构建自定义 rails 路由。我将方法创建为:

class RequestsController < ApplicationController
    def mainSearch
        .....etc
    end

并首先使用以下方法测试路线:

match '/mainSearch/:latitude', to: 'requests#mainSearch', via: 'get' 

running: localhost:3000/mainSearch/40.0

有效,但随后扩展到:

match '/mainSearch/:latitude/:longitude', to: 'requests#mainSearch', via: 'get'
running: localhost:3000/mainSearch/40.0/80.0

导致错误 No route matches [GET] "/mainSearch/40.0/80.0"

即使在定义的 rails 路由中它清楚地指出该路由存在:

这条路线显然应该有效,但它指出没有路线。如何缓解这种情况?

By default, dynamic segments don't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within a dynamic segment, add a constraint that overrides this.

往这边走:

get '/mainSearch/:latitude/:longitude',
  to: 'requests#mainSearch',
  constraints: { latitude: /\-?\d+\.\d+/, longitude: /\-?\d+\.\d+/ }