No route matches [GET] “/book/list”

半城伤御伤魂 提交于 2020-01-05 07:53:08

问题


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

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"**

Here's 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:


Your router config is all commented out, you need to add the rules yourself.

Guiders: Routing

Try add the below:

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

And access with: http://127.0.0.1:3000/books/list



来源:https://stackoverflow.com/questions/12444217/no-route-matches-get-book-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!