I am trying to using jQuery dialog to make a user sign in. I am using ajax and devise. After users sign in, the dialog windows should close. I put dialog("close") inside bind("ajax:success"), but it doesn't work and I get error:
"cannot call methods on dialog prior to initialization; attempt  to call method 'close'"
Code:
$(function(){
$(" #sign_in").click(function(){
     $('<div id="box" >').dialog({
        open: function(){ 
                 var that=this;
                 $(this).load("/users/sign_in",function(){ 
                    $("#new_user").bind("ajax:success",function(evt,data,status,xhr){
                    $("div#utility").html('welcome'+data.user+' |<a href="/users/sign_out" data-method="delete" rel="nofollow">sign out</a> ') ;
                    $(that).dialog('close');
                      })
               })
             },
        title: 'Sign in '
        });
   });
}) 
Can anyone help me figure out what the problem is?
 thanks
 
     
     
    