# Trouble creating a link or button to delete (more than basic delete from index)

**URL:** <https://www.ruby-forum.com/t/trouble-creating-a-link-or-button-to-delete-more-than-basic-delete-from-index/160936>\
**Category:** Rails\
**Created:** [February 21, 2009, 3:53am UTC](https://www.ruby-forum.com/t/trouble-creating-a-link-or-button-to-delete-more-than-basic-delete-from-index/160936 "2009-02-21T03:53:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![supasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@supasta](https://www.ruby-forum.com/u/supasta)\
**Post date:** [February 21, 2009, 3:53am UTC](https://www.ruby-forum.com/t/trouble-creating-a-link-or-button-to-delete-more-than-basic-delete-from-index/160936/1 "2009-02-21T03:53:33Z")

</div>

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  
[[X]](https://www.ruby-forum.com/entity_images/1?init_entity_id=1 "delete this")  
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  
[[X]](https://www.ruby-forum.com/entity_images/index/1?init_entity_id=1&method=delete "delete this")  
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  
[[X]](https://www.ruby-forum.com/entity_images/1?class=link_to_delete&confirm=Are+you+sure%3F&init_entity_id=1&title=delete+this)  
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  
[[X]](https://www.ruby-forum.com/entity_images/index/1?init_entity_id=1 "delete this")  
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

  
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 for either the link  
(preferred) or the button.

Any advice on how to get this working?

Thanks  
-Chris W

---

<div class="post-metadata">

**Author:** ![supasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@supasta](https://www.ruby-forum.com/u/supasta)\
**Post date:** [February 21, 2009, 4:03am UTC](https://www.ruby-forum.com/t/trouble-creating-a-link-or-button-to-delete-more-than-basic-delete-from-index/160936/2 "2009-02-21T04:03:29Z")

</div>

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
```
