【问题标题】:inherited resources: routes with nested resources继承资源:具有嵌套资源的路由
【发布时间】:2011-08-23 05:15:29
【问题描述】:

在我的 routes.rb 中我有:

resources :fire_preventions do
   get 'search_adv', :on => :collection
end

如何将它与继承的资源路由一起使用?

search_adv_collection_url 不起作用。

【问题讨论】:

    标签: ruby-on-rails inherited-resources


    【解决方案1】:

    由于只列出了一条路线,

    resources :fire_preventions do 
      get 'search_adv', :on => :collection 
    end
    

    是去掉附加块的缩写形式

    resources :fire_preventions do 
      collection do
        get 'search_adv'
      end
    end
    

    您应该可以使用search_adv_fire_preventions_path 和search_adv_fire_preventions_url。最好执行rake routes 来检查。

    【讨论】:

    • search_adv_fire_preventions_url 有效,但我想使用继承资源中的 url 助手,而 search_adv_collection_url 不起作用。
    • 你看过这些examples吗?似乎 collection_url 助手是上下文相关的。另外,如果你还没有看到这个screencast。
    【解决方案2】:

    您可以在命令行中执行rake routes。它将根据 routes.rb 打印所有可用路径

    【讨论】:

    • 我知道,但我想将继承的资源 url 助手与嵌套资源一起使用。
    • 请解释或展示您的嵌套资源代码示例。上面列出的路由不是嵌套的。
    猜你喜欢
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多