这里严重没有加起来..我的页面只是刷新,没有任何反应,它从来没有触及我的任何调试器,除了索引之外,我所有的方法都挂着。
我的html:
<%- for image in @images %>
<%= image.attachment_file_name %>
<%-# link_to_delete image, :url => destroy_image_admin_wysiwyg_path(image.id) %>
<%= link_to 'delete', { :url => destroy_image_image_path(image.id) },
#:confirm => 'Are you sure?',
:post => true
%>
<br />
<% end %>
我的控制器
def destroy_image
debugger
@img = Image.find(params[:id])
@img.destroy
respond_to do |format|
format.html { redirect_to admin_image_rotator_path }
end
end
我的路线:
map.resources :images, :member => { :destroy_image => :post }
我的令人作呕的 hack 很有效,一旦我找到更好的东西,我会立即更换
我将动作转移到我自己构建的更简单的控制器上。
将我的路线更改为:
admin.resources :wysiwygs, :member => { :destroy_image => :post }
改变了我的 html :
<%= link_to 'delete', :controller => "wysiwygs", :action => "destroy_image" %>
但是当我点击链接时..它带来了..show
动作?? fffffffffuuuuuu
作为报复,我只是将我的操作移到了显示操作,并在我的 html 中传递了一个隐藏字段。
<%= link_to 'delete', :controller => "wysiwygs", :action => "destroy_image", :hidden_field => {:value => image.id} %>
def show
# this was previously in destroy_image
@img = Image.find(params[:hidden_field][:value])
@img.destroy
respond_to do |format|
format.html { redirect_to admin_image_rotator_path }
end
end