Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 ActionController::UrlGenerationError在书中#新建_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 ActionController::UrlGenerationError在书中#新建

Ruby on rails 4 ActionController::UrlGenerationError在书中#新建,ruby-on-rails-4,Ruby On Rails 4,我的项目名是LibraryWebProject,我正在使用Eclipse和rails插件 routes.rb文件是 I getting the following error while I am accessing my new method like http://127.0.0.1:3000/book/new 我的控制器是 book\u controller.rbcontroller包含所有方法。我使用了Mysql数据库,gem是mysql2 LibraryWebPro

我的项目名是LibraryWebProject,我正在使用Eclipse和rails插件

routes.rb
文件是

    I getting the following error while I am accessing my new method like http://127.0.0.1:3000/book/new 
我的控制器是

book\u controller.rb
controller包含所有方法。我使用了Mysql数据库,gem是
mysql2

    LibraryWebProject::Application.routes.draw do
      get 'book/new'
      get 'book/list'
      get 'book/edit'
      get 'book/show_subjects'
      get 'book/show'
    end
我正在使用Rails4.0.3

最后,错误是

<h1>Add new book</h1>
<%= form_tag :action => 'create' %>
<p><label for="book_title">Title</label>:
<%= text_field 'book', 'title' %></p>
<p><label for="book_price">Price</label>:
<%= text_field 'book', 'price' %></p>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', {:action => 'list'} %>
。。。。。。。。。。。。。。。。。。。。。 没有路由匹配意味着什么?我无法找到解决方案,而且对rails和ruby来说都是新手

简单地替换为

Application Trace | Framework Trace | Full Trace
actionpack (4.0.3) lib/action_dispatch/journey/formatter.rb:39:in `generate'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:601:in `generate'

您可以用backtrace添加整个错误吗?以下是整个错误ActionView::Template::error(没有路由匹配{:action=>“create”,:controller=>“book”}):1:添加新书2:“创建“%$3:标题:4:

5:Price:app/views/book/new.erb:2:在`"app\u views\u book\u new\u erb\u586260966\u 11670096 `中呈现c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/gems/actionpack-4.0.3/lib/action\u dispatch/middleware/templates/rescues//trace.erb(0.0ms)呈现c:/RailsInstaller/Ruby1.9那么创建操作的路径在哪里?路径应该在routes中。rb获取“book/new/create”或获取“book/create”是否正确。你应该读一下Rails中的资源路由——我添加了LibraryWebProject::Application.routes.draw do resources:books end,但它给了我这个错误:没有路由匹配[GET]“/book/new”Rails.root:D:/railsapples/LibraryWebProject actionpack(4.0.3)lib/action\u dispatch/middleware/debug\u exceptions.rb:21:in
call'actionpack(4.0.3)lib/action\u dispatch/middleware/show\u exceptions.rb:30:in
call'railties(4.0.3)lib/rails/rack/logger.rb:38:in'call\u app'因为它不再是“book”,它应该是“books”。Is controller应该是复数形式??因为你喜欢书而不是书
No route matches {:action=>"create", :controller=>"book"}
Extracted source (around line #2):
  <h1>Add new book</h1>
  <%= form_tag :action => 'create' %>
  <p><label for="book_title">Title</label>:
  <%= text_field 'book', 'title' %></p>
  <p><label for="book_price">Price</label>:
Application Trace | Framework Trace | Full Trace
actionpack (4.0.3) lib/action_dispatch/journey/formatter.rb:39:in `generate'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:601:in `generate'
LibraryWebProject::Application.routes.draw do
  resources :books
end