views:

121

answers:

1

I want to create a drop_receiving_element where the :url contains javascript. Currently I just created a helper function and hard-coded the element in 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

That's pretty hackish and ugly, though. Ideally I'd like to do something like:

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

Or

formatted_whatever_path(:id => "some_javascript", :js)

Unfortunately, this doesn't seem possible because the url is escaped further down the call chain (in url_for, I believe). What are the alternatives?

A: 

What version of rails are you using? If you're on 2.3.8 then your "escaping" may simply be because of the "string addition bug": https://rails.lighthouseapp.com/projects/8994/tickets/4695-string-added-to-rails_helpers-gets-html-escaped

You can fix it either by finding ingenious hacks around it (eg encasing your string in "#{my_string}" to re-evalute it) or by downgrading to 2.3.5.

Taryn East