Chris Warren
2009-Feb-21 02:52 UTC
trouble creating a link or button to delete (more than basic delete from index)
Hi all, I''m using Rails 2.2.2. I''m trying to create a hyperlink that will delete an image when it''s clicked. However I need to 1. pass along a bit more info (init_entity_id) 2. call this from a different part of the app (the entity page has images on it, and clicking the delete link next to the image will delete that image) 3. specify the class of the link I can get it working if I don''t specify the class and if I skip the init_entity_id bit: <%= link_to ''[X]'', entity_image, :controller => entity_images'', :method => :delete, :confirm => ''Are you sure?'' %> I can probably work around the CSS issue by putting that in a span or something. I''d been planning on using the init_entity_id to return to the entity after the image is deleted. If there were a handy way to get back there with out passing along that entity''s ID I could get this working without the below mess.... I''ve tried <%= link_to ''[X]'', {:controller => ''entity_images'', :action => ''destroy'', :id => entity_image, :init_entity_id => @entity}, :confirm => ''Are you sure?'', :title => ''delete this'', :class => ''link_to_delete'' %> which creates <a href="/entity_images/1?init_entity_id=1" class="link_to_delete" onclick="return confirm(''Are you sure?'');" title="delete this">[X]</a> which shows the image instead of deleting it. I''ve tried <%= link_to ''[X]'', {:controller => ''entity_images'', :method => :delete, :id => entity_image, :init_entity_id => @entity}, :confirm => ''Are you sure?'', :title => ''delete this'', :class => ''link_to_delete'' %> which creates <a href="/entity_images/index/1?init_entity_id=1&method=delete" class="link_to_delete" onclick="return confirm(''Are you sure?'');" title="delete this">[X]</a> which lists all the images instead of deleting it. I''ve tried <%= link_to ''[X]'', :controller => ''entity_images'', :action => ''destroy'', :id => entity_image, :init_entity_id => @entity, :confirm => ''Are you sure?'', :title => ''delete this'', :class => ''link_to_delete'' %> which creates <a href="/entity_images/1?class=link_to_delete&confirm=Are+you+sure%3F&init_entity_id=1&title=delete+this">[X]</a> which shows the image instead of deleting it. I''ve tried <%= link_to ''[X]'', {:controller => ''entity_images'', :id => entity_image, :init_entity_id => @entity}, :method => :delete, :confirm => ''Are you sure?'', :title => ''delete this'', :class => ''link_to_delete'' %> which creates <a href="/entity_images/index/1?init_entity_id=1" class="link_to_delete" onclick="if (confirm(''Are you sure?'')) { var f = document.createElement(''form''); f.style.display = ''none''; this.parentNode.appendChild(f); f.method = ''POST''; f.action this.href;var m = document.createElement(''input''); m.setAttribute(''type'', ''hidden''); m.setAttribute(''name'', ''_method''); m.setAttribute(''value'', ''delete''); f.appendChild(m);var s document.createElement(''input''); s.setAttribute(''type'', ''hidden''); s.setAttribute(''name'', ''authenticity_token''); s.setAttribute(''value'', ''ad000f9b86a2ecabed45f0b1a103681db863d724''); f.appendChild(s);f.submit(); };return false;" title="delete this">[X]</a> which lists all the images instead of deleting it. Most other variations on link_to I''ve tried either produce outright errors in generating the link, or similarly just show the image or list all images. I''ve also tried <%= button_to ''[X]'', {:controller => ''trait_value_images'', :action => "destroy", :id => trait_value_image, :init_trait_value_id => @trait_value}, :method => :delete, :confirm => ''Are you sure?'', :title => ''delete this'' %> which creates <form method="post" action="/trait_value_images/7?init_trait_value_id=1" class="button-to"><div><input name="_method" type="hidden" value="delete" /><input onclick="return confirm(''Are you sure?'');" title="delete this" type="submit" value="[X]" /><input name="authenticity_token" type="hidden" value="ad000f9b86a2ecabed45f0b1a103681db863d724" /></div></form> which does do the delete, but the init_trait_value_id is not sent. Basically, I think I need a way to specify that the auto-generated mini-form include something like <input type="hidden" name="init_trait_value_id" value="1" /> for either the link (preferred) or the button. Any advice on how to get this working? Thanks -Chris W --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris
2009-Feb-21 03:02 UTC
Re: trouble creating a link or button to delete (more than basic delete from index)
It figures I''d finally find the solution about 2 minutes after giving up and posting to the list :/> If there were a handy way to > get back there with out passing along that entity''s ID I could get > this working without the below mess....What I needed was apparently just redirect_to request.referer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---