【问题标题】:Lookup static route from url从 url 查找静态路由
【发布时间】:2019-10-03 21:23:08
【问题描述】:

在我的 routes.rb 文件中,我有这个条目,命名空间位于 info:

    get 'account-pending', to: 'info/account_pendings#index'

如果我使用 /account-pending 的强静态路由,它当然会将我带到相应的页面,在浏览器 url 中带有 /account-pending

我可以这样要求这条路线:

url_helpers.info_account_pendings_path

但这会返回:

/info/account_pendings

我可以要求 info_account_pendings_path 并被 Rails 退回 /account-pending 吗?

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    您可能希望在路由文件中实际使用namespace 命令。

    namespace :info do
      get  'account-pending', controller: :account_pendings, action: index
    end
    

    实际上之前已经询问过获取命名路由的路径,尝试:Rails: Check output of path helper from console

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      • 2013-12-14
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多