【问题标题】:about rails route关于铁路路线
【发布时间】:2010-11-10 00:53:05
【问题描述】:

如果我使用

namespace :helpcenter do
  get "hh/logout"
  get 'hh/login'
end

它将匹配 url helpcenter/hh/logout

我的问题是如何让这些方法映射到 url /hh/logout 不包含模块名称

【问题讨论】:

  • 不太明白你的问题。你想达到什么目标?能详细点吗?
  • 所以您想将/hh/logout 匹配到herlpercenter_controllerhelpercenter::hh_controllerhh_controller?您的原始案例将使用helpcenter::hh_controller

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


【解决方案1】:

您可以使用范围来实现此目的:

scope :module => 'helpcenter' do
  resources :articles
end

这将为/articles/articles/new 等生成映射,而不是helpcenter/articles。然而,它仍然会路由到帮助中心命名空间中的文章控制器。例如:app/controllers/helpcenter/articles_controller.rb

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    相关资源
    最近更新 更多