删除Rails中的接收ID

时间:2011-01-06 09:23:20

标签: ruby-on-rails ajax jquery-plugins jquery

我目前有一个rails网页,它使用jRails和jQuery库来运行一些ajax函数。 到目前为止一切正常,包括delayedObserver插件,这表明jRails实际上正在使用。但是我的'drop_receiving_element'似乎不起作用。这是Rails代码:

    <%= drop_receiving_element drop_id,
      :onDrop => "function(drag_element, drop_element, event){
    if (confirm(\"#{escape_javascript(_('This will remove User from this Group, are you sure?'))}\"))
    {#{remote_function(:update => 'module_content',
    :url => {:controller => :projects,
    :action => :member_delete,
    :id => @project.id},
    :with => "'u=' + encodeURIComponent(drag_element.id)"
    )};}
    }",
      :accept => 'RolesUsersSelection',
      :hoverclass => "#{drop_class}_active"
  %>

这导致以下Javascript代码

  <script type="text/javascript"> 
//<![CDATA[
jQuery('#RemoveThisMember').droppable({accept:'RolesUsersSelection', drop:function(drag_element, drop_element, event){
    if (confirm("This will remove User from this Group, are you sure?"))
    {jQuery.ajax({data:'u=' + encodeURIComponent(drag_element.id), success:function(request){jQuery('#module_content').html(request);}, type:'post', url:'/of/projects/11/member_delete'});}
    }, hoverClass:'ProjectRoleDropDelete_active'})
//]]>
</script>

然而,我很难过为什么这不起作用。

这是jRails.rb中调用的函数

 def drop_receiving_element_js(element_id, options = {})
    #convert similar options
    options[:hoverClass] = options.delete(:hoverclass) if options[:hoverclass]
    options[:drop] = options.delete(:onDrop) if options[:onDrop]

    if options[:drop] || options[:url]
      options[:with] ||= "'id=' + encodeURIComponent(#{JQUERY_VAR}(ui.draggable).attr('id'))"
      options[:drop] ||= "function(ev, ui){" + remote_function(options) + "}"
    end

    options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }

    options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
    [:activeClass, :hoverClass, :tolerance].each do |option|
      options[option] = "'#{options[option]}'" if options[option]
    end

    %(#{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)});)
  end

有什么想法吗?

谢谢,

1 个答案:

答案 0 :(得分:0)

原来因为我已经切换到jQuery,

的参数
function(drag_element, drop_element, event)

不正确。这些是原型的正确参数。他们应该阅读

function (ui,event)

如果你使用jQuery库。