I getting the following error while I am accessing my new method like http://127.0.0.1:3000/book/new
我的项目名称是LibraryWebProject我正在使用带有rails插件的Eclipse
routes.rb
文件是
LibraryWebProject::Application.routes.draw do
get 'book/new'
get 'book/list'
get 'book/edit'
get 'book/show_subjects'
get 'book/show'
end
我的控制器是
book_controller.rb
控制器包含所有方法。我使用的是Mysql数据库,gem是mysql2
class BookController < ApplicationController
def list
@books = Book.find(:all)
end
def new
@book = Book.new
@subjects = Subject.find(:all)
end
def create
@book = Book.new(params[:book])
if @book.save
redirect_to :action => 'list'
else
@subjects = Subject.find(:all)
render :action => 'new'
end
end
def edit
@book = Book.find(params[:id])
@subjects = Subject.find(:all)
end
end
end
我的new.erb
文件是
<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'} %>
我正在使用Rails4.0.3
最后错误是
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>:
Rails.root:D:/ RailsAppsExamples / LibraryWebProject
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'
..................... 什么是无路线匹配的意思我无助于找到这个和新的铁路以及红宝石的解决方案
答案 0 :(得分:1)
您的路线错误
只需替换为
LibraryWebProject::Application.routes.draw do
resources :books
end