问题描述
rails2.1 不认 new_books_path,books是一个controller<h1>Listing books</h1><table> <tr> <th>Name</th> </tr><% for books in @books %> <tr> <td><%=h books.name %></td> <td><%= link_to 'Show', books %></td> <td><%= link_to 'Edit', edit_books_path(books) %></td> <td><%= link_to 'Destroy', books, :confirm => 'Are you sure?', :method => :delete %></td> </tr><% end %></table><br /><%= link_to 'New books', new_books_path %>出错信息为: NameError in Books#indexShowing books/index.html.erb where line #20 raised:undefined local variable or method `new_books_path' for #<ActionView::Base:0xb7371204>Extracted source (around line #20):17: 18: <br />19: 20: <%= link_to 'New books', new_books_path %>RAILS_ROOT: /home/jhzyb/myproject/testApplication Trace | Framework Trace | Full Traceapp/views/books/index.html.erb:20:in `_run_erb_47app47views47books47index46html46erb'app/controllers/books_controller.rb:7:in `index'
解决方案
new_book_path其实你可以在项目目录下执行rake routes,就会打印所有的路由
解决方案二:
routes.eb里有没有加上这句?map.resources :books