Something is seriously not adding up here.. My page just refreshes, nothing happens, it never touches any of my debuggers hanging out on all my methods except for index.
my 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 %>
my controller
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
My routes:
map.resources :images, :member => { :destroy_image => :post }
My disgusting hack that works that I will replace as soon as I find something better
I moved the action over to a simpler controller I built myself.
Changed my routes to :
admin.resources :wysiwygs, :member => { :destroy_image => :post }
Changed my html :
<%= link_to 'delete', :controller => "wysiwygs", :action => "destroy_image" %>
But when I clicked on the link..it brought up.. the show action ?? fffffffffuuuuuuu
I retaliated by just moving my action to the show action, and passing a hidden field in my 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
It seems you’re going down the wrong path here. If a
before_filteris blocking your action, figure out why. Useskip_before_filter :filter_nameif the filter is not needed.Don’t use
showactions or HTTP GET for deletes. Even if it works, it will confuse things down the road. Use a DELETE verb:map.resources :images, :member => { :destroy_image => :delete }pass it in the link helper:
And use
ImagesController#destroy_imageto perform the action. Better yet, consider using the standard RESTfulImagesController#destroywhichmap.resourcesgives you for free.