【问题标题】:Route to custom non-REST action路由到自定义非 REST 操作
【发布时间】:2011-05-26 11:09:54
【问题描述】:

我有带有 REST 路由的“文章”控制器。

我需要再做一个动作:

/articles/demo

它不属于 REST。

它只是呈现单独的页面,不消耗任何模型等。

当前 routes.rb 如下:

map.resources :articles
map.connect "articles/demo", :controller => "articles", :action => "demo"

不幸的是,它不起作用。

我明白了:

找不到 ID=demo 的文章

这里有什么问题?

【问题讨论】:

  • 顺便说一下,您的新 demo 操作不一定非 RESTful,因为它不是 GET、PUT、POST 和 DELETE 之一。 REST 是一种架构风格,可以由 HTTP 方法实现,但不仅限于它们。

标签: ruby-on-rails routing action


【解决方案1】:

这是因为它是在您的 map.resources 之前放置的之后。先入先选

map.connect "articles/demo", :controller => "articles", :action => "demo"
map.resources :articles

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多