Close Modalpopup with RJS

hi guys:

I'm scratching my head on this one: I have a twitter app where I'm
trying to open a modalpopup with a twitter sign in, get them to sign in,
then close the popup and refresh the main window. My code however
refreshes the main window with the popup window result, which I thought
was really strange:

application.html.erb

function OpenModalPopUP()
{
     window.showModalDialog('/sessions/create');
}

main page

<%= link_to "login via twitter", {:controller => "sessions/create"},
:onclick => "OpenModalPopUP()" %>

sessions/create

  def create

    oauth.set_callback_url(finalize_session_url)

    session['rtoken'] = oauth.request_token.token
    session['rsecret'] = oauth.request_token.secret

    redirect_to oauth.request_token.authorize_url
  end

sessions/finalize

  def finalize
    oauth.authorize_from_request(session['rtoken'], session['rsecret'],
params[:oauth_verifier])

    session['rtoken'] = nil
    session['rsecret'] = nil

    profile = Twitter::Base.new(oauth).verify_credentials
    user = User.find_or_create_by_screen_name(profile.screen_name)

    user.update_attributes({
      :atoken => oauth.access_token.token,
      :asecret => oauth.access_token.secret,
    })

    sign_in(user)
# page << "window.close()"
  redirect_to session[:return_to] rescue redirect_to :controller =>
"home"
# redirect_to :controller => "sessions/autoclose"
  end

As you can see, by the commented out code, I attempted to push
"window.close()" but it gave me an error message. i then tried to
redirect to another window which autoclosed, but when I did that, it
redirected the main window to autoclose as well. I'm a rails noob, so
I'm guessing that i have to do something after the redirect to shut
down the process after closing the window, otherwise it will run the
refresh on the main window? Please advise.

also, while i'm at it, do you know how I can resize the modalpopup?

Thanks...chris

Here is something to close modalbox, rjs:

page.call 'Modalbox.hide();'

Chris Habgood wrote:

Here is something to close modalbox, rjs:

page.call 'Modalbox.hide();'

Thanks Chris... this is what I get when I try that:

undefined local variable or method `page' for
#<SessionsController:0xb6e8a204>

any ideas?

Chris Kalaboukis wrote:

Chris Habgood wrote:

Here is something to close modalbox, rjs:

page.call 'Modalbox.hide();'

Thanks Chris... this is what I get when I try that:

undefined local variable or method `page' for
#<SessionsController:0xb6e8a204>

any ideas?

also tried this:

    render :update do |page|
      page.call 'Modalbox.hide();'
    end

but then got this error

try {
Modalbox.hide();();
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Modalbox.hide();();'); throw e }

When i closed the modal box manually, it refreshed the main window with
the saem error

can anyone help me here. i assume that there is a way to do this...

You can see this being the error

Modalbox.hide();();

Use this way

render :update do |page|
   page << 'Modalbox.hide();'
end

OR this..

render :update do |page|
  page.call 'Modalbox.hide'
end

regards,
Sur
http://crimson9.com

Sur Max wrote:

You can see this being the error

Modalbox.hide();();

Use this way

render :update do |page|
   page << 'Modalbox.hide();'
end

OR this..

render :update do |page|
  page.call 'Modalbox.hide'
end

regards,
Sur
http://crimson9.com

Tried it both ways, I still get this:

this:

render :update do |page|
   page << 'Modalbox.hide();'
end

gives this:

try {
Modalbox.hide();
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Modalbox.hide();'); throw e }

and this

render :update do |page|
  page.call 'Modalbox.hide'
end

gives this:

try {
Modalbox.hide();
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Modalbox.hide();'); throw e }

Any ideas? Thanks for your help so far....

Thanks...Chris