【问题标题】:Rails Routing like http:://host.com/controller-action-controllerRails 路由,如 http://host.com/controller-action-controller
【发布时间】:2012-01-18 22:12:04
【问题描述】:

我尝试使用另一个分隔符创建 URL,而不是“/”,例如“-”

来自http://host.com/category/food => http://host.com/category-food

谁能帮帮我?

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby routes delimiter divider


    【解决方案1】:

    这样的东西应该可以在 Rails 3.0 及更高版本中使用:

     get 'category-:id' => 'categories#show', :as => 'show_category'
    

    然后你可以使用<%= link_to 'Category', show_category_path(category) %>链接到它

    【讨论】:

      【解决方案2】:

      将'/category-food' 匹配到:'category#food'。

      【讨论】:

      • 欢迎您。很高兴为您提供帮助。考虑接受答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      • 2020-07-13
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多