没有路线匹配[GET]“/ book / list”

时间:2012-09-16 03:23:01

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

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

class BookController < ApplicationController

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

end

我还在模型下创建了名为book.rb的模型,并在list.rhtml文件夹中创建了\app\views\book。当我点击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

1 个答案:

答案 0 :(得分:4)

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

Guiders: Routing

尝试添加以下内容:

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

并访问:http://127.0.0.1:3000/books/list