Forum: Ruby on Rails perooidically_call_remote

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2008-10-28 22:27
I am using the following for to peroidically call back to the control to
see if a certain amount of time has passed:

in .rhtml
<%= periodically_call_remote :url => {
:action => 'session_expiry' },
:update => '' %>

in controller
 if !session[:expire].blank?
   @time_left = (session[:expire][:expires] - Time.now).to_i
 else
   @time_left = 0
 end

 if @time_left.to_i < 0 or @time_left == 0
   flash[:notice] = "<b style = 'color: red;'>You have been logged out
due
     to inactivity</b>"
   session[:user] = nil
   redirect_to :action => 'login'
 end

The idea being that if too much time has passed the user gets signed out
and get kicked back to the login page. Everything work right, except the
bit of code that check to see if an hour has passed since the users last
action and then it is supposed to redirect_to a login form. The problem
is that when it gets to that redirect_to it seems to skip right over it
and not do anything, even worse, it allows the user to continue to be
logged in. Has anyone used peroidically_call_remote before and has
similar issues and how did you fix them? Thanks,

-S
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-28 22:39
(Received via mailing list)
On Oct 28, 9:27 pm, Shandy Nantz <rails-mailing-l...@andreas-s.net>
wrote:
> The idea being that if too much time has passed the user gets signed out
> and get kicked back to the login page. Everything work right, except the
> bit of code that check to see if an hour has passed since the users last
> action and then it is supposed to redirect_to a login form. The problem
> is that when it gets to that redirect_to it seems to skip right over it
> and not do anything, even worse, it allows the user to continue to be
> logged in. Has anyone used peroidically_call_remote before and has
> similar issues and how did you fix them? Thanks,

This has nothing to do with periodically_call_remote and everything to
do with it being an ajax request.
If you want to redirect from an ajax request you need to use rjs (ie
remove the update option from periodically_call_remote) and use
page.redirect_to from the rjs

Fred
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2008-10-29 15:30
Frederick Cheung wrote:
>
> This has nothing to do with periodically_call_remote and everything to
> do with it being an ajax request.
> If you want to redirect from an ajax request you need to use rjs (ie
> remove the update option from periodically_call_remote) and use
> page.redirect_to from the rjs
>
> Fred

That fixed it, thanks,

-S
This topic is locked and can not be replied to.