1

我正在使用 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
4

1 回答 1

4

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

向导:路由

尝试添加以下内容:

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

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

于 2012-09-16T03:27:11.137 回答