Topic: Variable url in an Ajax call

I'm looking for an elegant way to do the following:

drop_receiving_element('some_class',                                               
  :accept => 'some_other_class',
  :url    => formatted_whatever_path( SOMETHING_BASED_ON_WHATEVER_IS_BEING_DROPPED ) )

So is there anyway to get the path to be variable based on client-side javascript?  So something like
formatted_whatever_path(:id => "some_javascript", :js)

Re: Variable url in an Ajax call

Since I didn't get a response to this question I ended up just hardcoding some custom javascript into a helper function like so

def create_classification_droppable(droppable_id, classification)
        "<script type='text/javascript'>
      //<![CDATA[
        Droppables.add('#{droppable_id}', {accept:'lead', onDrop:function(element){new Ajax.Request('/leads/' + (element.id.split('_').last()) + '.js', {asynchronous:true, evalScripts:true, method:'put', parameters:'lead[classification]=#{classification}&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')})}})
      //]]>
    </script>"
    end

If anyone can think of a better solution I'd love to hear it because this one is kind of ugly...

I'll write a small account of my experiences while trying to figure this out in the General section.

Re: Variable url in an Ajax call

So you want the url to be polymorphic based upon whatever Ruby class i being manipulated by this method?

Re: Variable url in an Ajax call

cherring wrote:

So you want the url to be polymorphic based upon whatever Ruby class i being manipulated by this method?

Not quite.  I want the URL to be a javascript string such that the url is based on whatever is being dropped into the Droppable, like so:

new Ajax.Request('/leads/' + (element.id.split('_').last()) + '.js'...

I can't do that using the :url parameter of drop_receiving_element because it gets escaped somewhere in the call chain (url_for or remote_function?  I can't remember)

I guess the simplest way I can put it is I want to create a drop_receiving_element where the :url contains javascript.

Last edited by skcuslleb (2009-04-27 00:57:45)