代码之家  ›  专栏  ›  技术社区  ›  dennismonsewicz

Rails:在URL中设置参数

  •  2
  • dennismonsewicz  · 技术社区  · 11 年前

    我有一条这样的路线 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。可能只是有一个“星期一的案例”,但我不确定我做错了什么。

    1 回复  |  直到 11 年前
        1
  •  2
  •   Pierre-Louis Gottfrois    11 年前

    试着简单地做:

    school_path([School.first, 'football'])
    

    任何其他 params 你在结尾这样加:

    school_path([School.first, 'football'], foo: :bar)
    

    将作为 http://localhost:3000/schools/football?foo=bar