开发者

Dropping Receiving ID in Rails

I currently have a rails webpage that uses the jRails and the jQuery library to run some ajax functions. So far everything is working, including the delayedObserver plugin, which suggests that jRails is actually being put to use. However my 'drop_receiving_element' doesn't seem to work. This the Rails code:

    <%= 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开发者_Go百科=' + encodeURIComponent(drag_element.id)"
    )};}
    }",
      :accept => 'RolesUsersSelection',
      :hoverclass => "#{drop_class}_active"
  %>

Which results in the following Javascript Code

  <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>

Yet I'm stumped as to why this isn't working.

This is the function called in the 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

Any ideas?

Thanks,


Turns out because I've switched over to jQuery, the parameters for

function(drag_element, drop_element, event)

were incorrect. Those are the correct parameters for prototype. They should read

function (ui,event)

if your using the jQuery library.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜