我有get "/schools/:id/:sport_name" => "schools#show"
之类的路线,但当我运行school_path(School.first, sport_name: "football")
时,生成的路线为http://localhost:3000/schools/slug-name-here?sport_name=football
......
我认为您可以传入匹配的参数名称,而URL生成器会根据选项集构建URL。可能只是有“星期一的情况”,但我不确定我做错了什么。
答案 0 :(得分:2)
尽量做到:
school_path([School.first, 'football'])
您最后添加的任何其他params
如下:
school_path([School.first, 'football'], foo: :bar)
将作为http://localhost:3000/schools/football?foo=bar