【问题标题】:No route matches [GET] "/book/list"没有路线匹配 [GET] "/book/list"
【发布时间】:2012-09-16 03:23:00
【问题描述】:

我正在使用 Rails 3.2.7。我有一个控制器和一个动作,如下所示:

class BookController < ApplicationController

   def list
      @books = Book.find(:all)
   end

end

我还在模型下创建了一个名为 book.rb 的模型,并在 \app\views\book 文件夹中创建了一个 list.rhtml。当我点击http://127.0.0.1:3000/book/list 时,我收到了这个错误:

No route matches [GET] "/book/list"**

这里是config/routes.rb

Ravi::Application.routes.draw do
  # The priority is based upon order of creation:
  # first created -> highest priority.

  # rest of the explanations in default "config/routes.rb"
end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 rails-routing


    【解决方案1】:

    您的路由器配置已全部注释掉,需要您自己添加规则。

    Guiders: Routing

    尝试添加以下内容:

    resources :books do
      get 'list', :on => :collection
    end
    

    并通过以下方式访问:http://127.0.0.1:3000/books/list

    【讨论】:

    • 非常感谢,我修改了那个,但我得到了这个错误,请看这里的屏幕截图postimage.org/image/subaz7t8n
    • +1 用于链接到非常好的 Rails 路由指南。还有评论。
    • 我这样做了,即将文件重命名为 list.erb.html ,但仍然是相同的异常。
    • @PreethiJain,抱歉,应该是list.html.erb
    猜你喜欢
    • 2016-06-15
    • 2011-12-11
    • 2015-09-27
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多