开发者

Rails 3: jquery.idletimeout plugin's remote requests are failing

I'm using the jquery.idletimeout plugin with the following in my application.js:

jQuery.idleTimeout('#session_timeout', '#session_timeout a', {
  idleAfter: 600,
  pollingInterval: 15,
  keepAliveURL: '/session',
  serverResponseEquals: 'OK',
  // Additional "on" event functions...
});

Here is some relevant Ruby code:

# /app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
  respond_to :html, :only => [:new, :create, :destroy]
  respond_to :js, :only => [:show]

  # Used by the jQuery.idleTimeout plugin
  def show
    if current_user_account # method to check for logged in user
      render :text => 'OK'
    else
      render :text => 'NOT OK', :status => 404
    end
  end
end

# /config/routes.rb
resource :session
resources :sessions
get 'login' => "sessions#new", :as => "login"  
get 'logout' => "sessions#destroy", :as => "logout"

However, when a page is loaded, my browser's (Chrome) Network console is showing the following (and Firefox's shows an "Aborted" status):

Rails 3: jquery.idletimeout plugin's remote requests are failing

Requests from the plugin to '/session' are made, but something is messing up. The plugin is seeing these 5 responses as failed and is therefore aborting. To test, I created the following remote link to the same controller/action:

<%= link_to 'test remote session', session_path, :remote => true %>

If I click this everything seems to work fine. (Last request in screenshot above.) I noticed in my development.log file a difference between the plugin's request and the remote link's request:

# Request from plugin:
Started GET "/session" for 127.0.0.1 at 2011-06-16 13:31:33 -0400
Processing by SessionsController#show as 
...
Rendered text template (0.0ms)
Completed 200 OK in 898ms (Views: 1.0ms | ActiveRecord: 21.8ms | Sphinx: 0.0ms)

# Request from remote link:
Started GET "/session" for 127.0.0.1 at 2011-06-16 13:33:36 -0400
Processing by SessionsController#show as JS
...
Rendered text template (0.0ms)
Completed 200 OK in 918ms (Views: 1.0ms | ActiveRecord: 2.5ms | Sphinx: 0.0ms)

The remote link request shows "...#show as JS" while the plugin's doesn't include the "JS". Not sure if this is part of the problem...

Anyway, this is long, but does any开发者_开发技巧one see what the issue is? Thank you.


I had the same exact problem. idleTimeout supports an AJAXTimeout option, which defaults to 250ms, but apparently it's too slow (or the default doesn't actually work). In either case, if you just increase that to 500 or some slightly larger number, it works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜