B Seven
B Seven

Reputation: 45941

How to exclude a single controller action from a filter in Rails 3.07?

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :check_session_expiry, :except => :login

How do you exclude a single controller's (the users controller, for example) login action?

Upvotes: 2

Views: 1517

Answers (3)

ayckoster
ayckoster

Reputation: 6847

I would just redefine check_session_expiry in your controller to be an empty method.

  class UserController < ...
    ...
    private
    def check_session_expire
      # optional if other actions shall still use the filter
      super unless self.action == 'login'
    end
  end

Upvotes: 2

Deradon
Deradon

Reputation: 1787

First, I'm not on a machine with rails to test it, but the following should work:

class UserController < ApplicationController
  skip_filter :check_session_expiry, :only => :foo

  # following is DEPRECATED as far as I know
  #skip_before_filter :check_session_expiry, :only => :foo

  def foo
  end
end

Upvotes: 5

Dex
Dex

Reputation: 12759

class ApplicationController < ActionController::Base
  before_filter :check_session_expiry


  def check_session_expiry
     return true if self.class != UsersController && self.action == "login"
     # do your thing
  end

Upvotes: 2

Related Questions