没有路由匹配 [GET] "/book/list"; [英] No route matches [GET] "/book/list"
本文介绍了没有路由匹配 [GET] "/book/list";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 Rails 3.2.7.我有一个控制器和一个动作,如下所示:
I am using Rails 3.2.7. I have a controller and a action as it's shown below:
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
时,我收到此错误:
I also created a model with the name book.rb
under model and a list.rhtml
inside \app\views\book
folder. When I hit http://127.0.0.1:3000/book/list
, I am getting this error:
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
推荐答案
你的路由器配置都被注释掉了,你需要自己添加规则.
Your router config is all commented out, you need to add the rules yourself.
尝试添加以下内容:
resources :books do
get 'list', :on => :collection
end
并通过以下方式访问:http://127.0.0.1:3000/books/list
这篇关于没有路由匹配 [GET] "/book/list";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文