# Restful ajax in droppables

**URL:** <https://www.ruby-forum.com/t/restful-ajax-in-droppables/132691>\
**Category:** Rails\
**Created:** [March 23, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/restful-ajax-in-droppables/132691 "2008-03-23T15:36:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [March 23, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/restful-ajax-in-droppables/132691/1 "2008-03-23T15:36:35Z")

</div>

How should i write a nice restful route for an ajax-call that adds a  
tag to a particular game. I have games, they can have (multiple) tags,  
and you can edit those in the admin\_area, for which i have written  
these resources:

map.namespace(:admin) do |admin|  
admin.resources :games  
admin.resources :tags, :member =\> {:add\_to\_game =\> :post}  
end

which gives me admin\_games\_path etc. By the way, is that (the admin/  
tags-controller) a good place for a method to add a tag to a game?  
Should it be elsewhere (in the admin/game-controller for example)?

My problem is how i should write this in a drop\_receiving\_element tag,  
especially how i can pass a put-method with it, since that seems more  
logical in a restful-context. I had this in my routes (instead of  
above)

map.namespace(:admin) do |admin|  
admin.resources :games  
admin.resources :tags, :member =\> {:add\_to\_game =\> :put}  
end

but i didn’t know how to write that into my droppable-tag:

drop\_receiving\_element div\_id, :url =\>  
add\_to\_game\_admin\_tag\_path(someid), :hoverclass =\> ‘hover’

that one only seems to generate (ajax) post-requests, and i didn’t  
succeed in passing a :method =\> :put with the url correcly.

How should i write that?

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [March 23, 2008, 9:52pm UTC](https://www.ruby-forum.com/t/restful-ajax-in-droppables/132691/2 "2008-03-23T21:52:19Z")

</div>

passing in a method in the options-hash seems to work now, didn’t get  
that to work earlier.

what i’m still confused about is how to use my resource-paths in this  
line

= drop\_receiving\_element :delete\_bin, :url =\>  
admin\_tag\_path(needs\_an\_id\_here), :method =\> :delete, :hoverclass =\>  
‘hover’

the admin\_tag\_path needs an id to be able to route to admin/  
tags#destroy, is it even possible to use that (path)helper\_method  
here? (since i don’t have the id yet). adding a collection to the  
resource that generates a route without an id to destroy a tag doesn’t  
seem like the right way to go.
