【问题标题】:Hiding a resource name in FriendlyID slug在 FriendlyID slug 中隐藏资源名称
【发布时间】:2012-06-20 10:30:54
【问题描述】:

我正在使用 FriendlyID 为我的一些模型生成 slug。

要使用 FriendlyID 文档 (http://rubydoc.info/github/norman/friendly_id/master/frames) 中提供的示例,我的网址目前如下所示:

http://localhost:3000/cities/seattle/restaurants/joes-diner

鉴于在我的情况下,一个城市除了餐馆什么都没有,我正在寻找一种方法来删除 URL 中的“restaurants”位,使其看起来像这样:

http://localhost:3000/cities/seattle/joes-diner

或者如果可能的话

http://localhost:3000/seattle/joes-diner

实现这一目标的最佳方法是什么 - 如果这样做是可取的?我可以想象最后一个选项可能会带来一些复杂性。

【问题讨论】:

标签: ruby-on-rails routes friendly-id


【解决方案1】:

您可以在http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing#controller-namespaces-and-routing找到解决您的问题的方法

您可以使用:path => "" 执行此任务。

问候!

【讨论】:

    【解决方案2】:

    带有规格和正确编辑\更新等的解决方案在这里:

    http://jasoncodes.com/posts/rails-3-nested-resource-slugs#solution

    【讨论】:

      猜你喜欢
      • 2018-03-23
      • 2012-03-21
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-30
      • 1970-01-01
      相关资源
      最近更新 更多