The simplest way to disable sessions in Rails is to use session :o ff (see ActionController::SessionManagement::ClassMethods).

session :o ff

To disable session suport only for a specific controller add session :o ff to that controller

class MyController < ApplicationController
    session :o ff
end

Written like that, sessions are disabled for all actions on this controller.

Like filters, you can specify :o nly and :except clauses to restrict subset. The following code will disable session for first_action and third_action, but not for second_action.

class MyController < ApplicationController
  session :o ff, :o nly %w(first_action third_action)

  def first_action
  end

  def second_action
  end

  def third_action
  end
end

Same could be achived with session :o ff, :except => :second_action.

The session options are inheritable, so to disable sessions for the entire application add session :o ff to ApplicationController.

class ApplicationController < ActionController::Base
    session :o ff
end

session :disabled => true

The downside of above approach is that if you disable sessions in ApplicationController with session :o ff you can't enable them later on.

But luckily there is a cure for that. Instead of session :o ff add this line session :disabled => true to ApplicationController.

class ApplicationController < ActionController::Base
    session :disabled => true
end

Now, you can re-enable session support in an inheriting controller with session :disabled => false.

class MyController < ApplicationController
    session :disabled => false
end

Further reading

Technorati Tags: ,

Trackback

only 1 comment untill now

  1. Thanks for information.
    many interesting things
    Celpjefscylc

Add your comment now