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:
我想创建一个drop_receiving_element,其中:url包含javascript。目前我刚刚创建了一个辅助函数并对元素进行了硬编码:
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?
不幸的是,这似乎不可能,因为url在调用链中进一步转义(在url_for中,我相信)。有哪些替代方案?
1 个解决方案
#1
0
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
您使用的是哪种版本的导轨?如果您使用的是2.3.8,那么您的“转义”可能只是因为“字符串添加错误”:https://rails.lighthouseapp.com/projects/8994/tickets/4695-string-added-to-rails_helpers -gets-HTML转义
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.
您可以通过查找周围的巧妙黑客来修复它(例如将您的字符串包含在“#{my_string}”中以重新评估它)或降级到2.3.5。
#1
0
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
您使用的是哪种版本的导轨?如果您使用的是2.3.8,那么您的“转义”可能只是因为“字符串添加错误”:https://rails.lighthouseapp.com/projects/8994/tickets/4695-string-added-to-rails_helpers -gets-HTML转义
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.
您可以通过查找周围的巧妙黑客来修复它(例如将您的字符串包含在“#{my_string}”中以重新评估它)或降级到2.3.5。