# Perooidically\_call\_remote

**URL:** <https://www.ruby-forum.com/t/perooidically-call-remote/152005>\
**Category:** Rails\
**Created:** [October 28, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/perooidically-call-remote/152005 "2008-10-28T22:27:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 28, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/perooidically-call-remote/152005/1 "2008-10-28T22:27:17Z")

</div>

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] = “**You have been logged out  
due  
to inactivity**”  
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

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 28, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/perooidically-call-remote/152005/2 "2008-10-28T22:39:00Z")

</div>

On Oct 28, 9:27 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 29, 2008, 3:30pm UTC](https://www.ruby-forum.com/t/perooidically-call-remote/152005/3 "2008-10-29T15:30:41Z")

</div>

Frederick C. 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
