Ajax Call redirect to a full page refresh

125 views
Skip to first unread message

MrBa...@googlemail.com

unread,
Mar 6, 2007, 11:00:23 AM3/6/07
to Ruby on Rails: Talk
Hi,

Let s assume my controller gets a ajax call... I will start the
process to to the appropriate actions...
During the process I discover that the changes are too complex and I
cannot provide the user the response with just an ajax response...
instead I would need a full page fresh...

Unfortunelty, I ve got no idea how to solve this... :-(

Thanks a lot in advance...

-
Volker

wesgarrison

unread,
Mar 6, 2007, 11:13:09 AM3/6/07
to Ruby on Rails: Talk
On Mar 6, 10:00 am, "MrBana...@googlemail.com"

-------
def my_action
if changes_are_too_complex
redirect_to :action => 'show' ...
else
# auto-render my_action.rjs template if its there
end
end

If you don't do anything, you'll get the template automatically. If
you do a redirect, the auto template will get skipped.

-- Wes


javier ramirez

unread,
Mar 6, 2007, 11:19:31 AM3/6/07
to rubyonra...@googlegroups.com

> Let s assume my controller gets a ajax call... During the process I discover that the changes are too complex and I
> cannot provide the user the response with just an ajax response...instead I would need a full page fresh...
>
since you have in "page" the object representing your javascript
document, you could just send a client-side redirect to that object and
the browser would do the rest.

regards,

javier ramirez

--
--------
Estamos de estreno... si necesitas llevar el control de tus gastos visita http://www.gastosgem.com !!Es gratis!!

Jason Roelofs

unread,
Mar 6, 2007, 11:50:59 AM3/6/07
to rubyonra...@googlegroups.com
Unfortunately, I don't believe that will work. From what I've seen, what Wes' solution will do is redraw the entire page inside of the element specified in Ajax.Update, leading to a very odd looking site-in-site effect.

The best way I could think of doing it was to send RJS back that does a simple "document.location = page_url", forcing the browser to reload the page from scratch.

Jason

javier ramirez

unread,
Mar 6, 2007, 12:06:54 PM3/6/07
to rubyonra...@googlegroups.com

> Unfortunately, I don't believe that will work. From what I've seen,
> what Wes' solution will do is redraw the entire page inside of the
> element specified in Ajax.Update, leading to a very odd looking
> site-in-site effect. The best way I could think of doing it was to
> send RJS back that does a simple "document.location = page_url",
> forcing the browser to reload the page from scratch.
if you are not using any "update" parameter when invoking ajax (and if
you use update you can change that easily), you can directly do
page.redirect_to whatever

you can do that in the rjs or directly on the controller by using render
:update. Behind the scenes it will do domething pretty similar to what
you propose, which is changing window.location.href. The advantage is
you can use the parameters of redirect_to and you don't need to
implement anything at the server side

regards,

j

Carl Lerche

unread,
Mar 6, 2007, 12:27:54 PM3/6/07
to rubyonra...@googlegroups.com
I would do something like

def my_action
if changes_are_too_complex
render :update do |page|
page.redirect_to :action => "show"
end
end
end

Also with the default my_action.rjs template (as indicated above).

-carl

On 3/6/07, wesgarrison <wes.ga...@gmail.com> wrote:
>


--
EPA Rating: 3000 Lines of Code / Gallon (of coffee)

wesgarrison

unread,
Mar 6, 2007, 3:24:52 PM3/6/07
to Ruby on Rails: Talk
On Mar 6, 10:50 am, "Jason Roelofs" <jameskil...@gmail.com> wrote:
> Unfortunately, I don't believe that will work. From what I've seen, what
> Wes' solution will do is redraw the entire page inside of the element
> specified in Ajax.Update, leading to a very odd looking site-in-site effect.
>
> The best way I could think of doing it was to send RJS back that does a
> simple "document.location = page_url", forcing the browser to reload the
> page from scratch.
>
> Jason
>
> On 3/6/07, wesgarrison <wes.garri...@gmail.com> wrote:
>
>
>
> > On Mar 6, 10:00 am, "MrBana...@googlemail.com"
> > <MrBana...@googlemail.com> wrote:
> > > Hi,
>
> > > Let s assume my controller gets a ajax call... I will start the
> > > process to to the appropriate actions...
> > > During the process I discover that the changes are too complex and I
> > > cannot provide the user the response with just an ajax response...
> > > instead I would need a full page fresh...
>
> > > Unfortunelty, I ve got no idea how to solve this... :-(
>
> > > Thanks a lot in advance...
>
> > > -
> > > Volker
>
> > -------
> > def my_action
> > if changes_are_too_complex
> > redirect_to :action => 'show' ...
> > else
> > # auto-render my_action.rjs template if its there
> > end
> > end
>
> > If you don't do anything, you'll get the template automatically. If
> > you do a redirect, the auto template will get skipped.
>
> > -- Wes

I could'a sworn that I'd used redirect_to instead of
page.redirect_to.
Anyway, you can do your processing to determine what "too complex"
means, then either render a redirect, render some js in the
controller, or pass it to a .rjs template.

-- Wes

Jon Garvin

unread,
Mar 6, 2007, 6:40:26 PM3/6/07
to rubyonra...@googlegroups.com
My guess is that you just want cause the entire page to refresh.... so
here is another option...

def my_action
#do stuff


if changes_are_too_complex
render :update do |page|

page.replace_html 'message_to_user_div', '<strong>Reloading
Page...</strong>'
page.call 'location.reload'
end
else
#do other stuff
end
end

Reply all
Reply to author
Forward
0 new messages