【问题标题】:How to translate and modify map.resources :document如何翻译和修改 map.resources :document
【发布时间】:2009-06-08 06:45:41
【问题描述】:
map.resources :document

添加这条路线后,我现在有一个自动的“edit_document_path”。我想把它改成“annotate_document_path”?如果我添加新的视图和控制器方法,它会自动选择它吗?它是如何从资源路径转换为这些“路径”符号的?

【问题讨论】:

    标签: ruby-on-rails resources routes


    【解决方案1】:

    贾罗德是正确的。 map.resources 默认只添加 RESTful 路由。要获得您想要的路线,该行应为

    map.resources :document, :member => {:annotate => :get}
    

    :member 表示此路由将具有关联的 document_id,:annotate 将是 url 的一部分,而 :get 是用于访问此路由的 HTTP 方法。

    通过这一行,您应该可以访问 annotate_document_path(document_id) 辅助方法。

    【讨论】:

      【解决方案2】:

      map.resources 添加 RESTful 路由。您正在寻找命名路线。 More info at RailsGuides.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-02-20
        • 2018-08-23
        • 1970-01-01
        • 2015-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-18
        相关资源
        最近更新 更多