当我点击笔记的编辑按钮时导致此错误的原因是什么?删除按钮工作正常。我用脚手架创建了注释对象。
index.html.erb
<% @notes.each do |note| %>
<%= note.detail %>
<%= button_to 'Delete', note, :confirm => 'Are you sure?', :method => :delete %>
<%= button_to 'Edit', edit_note_path(note) %>
<% end %>
notes_controller.rb
before_filter :check_ownership, :except => [:new, :create, :index, :edit]
def edit
@note = Note.find(params[:id])
end
错误
ActiveRecord::RecordNotFound in NotesController#192
Couldn't find Note with ID=edit
../app/controllers/notes_controller.rb:248:in `check_ownership'
Parameters:
{"id"=>"edit"}
EDIT 配置/ routes.rb中
map.resources :notes
所有其他笔记路线都可以正常工作。
感谢您阅读
答案 0 :(得分:2)
脚手架控制器的“编辑”操作,以及defult路由支持“编辑”为GET而不是POST请求。
如果您使用的是link_to
而不是button_to
,那么事情应该会有效。
或者,更改包含button_to
-
<%= button_to 'Edit', edit_note_path(note), :method => :get %>