【问题标题】:Can the route "match 'welcome/index' => 'welcome#index'" be shortened?可以缩短路线“匹配'welcome/index' => 'welcome#index'”吗?
【发布时间】:2012-04-13 14:23:04
【问题描述】:

我有:

match 'welcome/index' => 'welcome#index'

只有一个欢迎操作/页面是索引。所以我可以有吗

match 'welcome/' => 'welcome#index'

(假设任何地方都不存在其他欢迎/目录)或其中之一:

match 'welcome' => 'welcome#index'

match '/welcome' => 'welcome#index'

match '/welcome/' => 'welcome#index'

匹配是否像某种正则表达式一样工作,我可以加入斜杠以确保查找目录的内容吗?

【问题讨论】:

  • 我现在无法运行服务器 + 我也在寻找最佳实践

标签: ruby-on-rails ruby-on-rails-3 routes


【解决方案1】:

这对你很有效:

match '/welcome' => 'welcome#index'

并且“/welcome”代表您对某些控制器操作的路径名。它与任何欢迎目录无关。

例如,如果您希望 Welcome#index 的链接为 localhost:3000/imhere

match '/imhere' => 'welcome#index'

【讨论】:

    猜你喜欢
    • 2014-02-07
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    相关资源
    最近更新 更多