你好我試圖在數據庫中編輯/更新一些數據,但我不斷收到以下錯誤:路線的編輯工作不紅寶石
No route matches [POST] "/books/11/edit"
我嘗試添加一些不同的線routes.rb中如
post 'books/edit'
等..但我沒有運氣。這是我目前的Routes文件。
Rails.application.routes.draw do
resources :books, :only => [:new, :create, :edit, :index]
resources :details, :only => [:new, :edit]
resources :members
devise_for :users
get 'page/books'
get 'page/about'
get 'page/contact'
get 'page/home'
post "details/new"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'page#home'
我的防守編輯是:
def edit
@book = Book.find(params[:id])
end
和表單正在使用所用的是:
<h4> Book Details </h4>
<p> Edit This Current Book </p>
<%= form_for @book do |f| -%>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title, autofocus: true %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_field :description, autofocus: true %>
</div>
<div class="field">
<%= f.label :isbn_number %><br />
<%= f.text_field :isbn_number, autofocus: true %>
</div>
<div class="field">
<%= f.label :author %><br />
<%= f.text_field :author, autofocus: true %>
</div>
<div class="field">
<%= f.label :status %><br />
<%= f.text_field :status, autofocus: true %>
</div>
<br />
<%= f.submit "Edit Book" %>
<% end -%>
<br />
==加入這個== 防守更新後曾任職:
def update
@book = Book.find(params[:id])
@book.update_attributes(book_params)
redirect_to new_book_path
end
什麼時候出現這個錯誤?是否當你嘗試提交表單? – mikej
我無法進入表單頁面,只要我點擊編輯應該鏈接到編輯頁面發生錯誤 – Roland
好吧,聽起來就像編輯鏈接的問題。這應該是生成GET請求而不是POST。你是否在用'link_to'編輯',edit_book_path(book)'? – mikej