Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Pass blocks to before/after filter methods using :with option

#946

I recently found a need to have an application-wide before_filter perform differently from certain controllers. I thought it could be useful to do something like:


class ApplicationController < ActionController::Base
  protected
    def redirect_unless_logged_in
      block_given? ? yield(self) : redirect_to(login_path)
    end
end

class SpecialController
  before_filter :redirect_unless_logged_in, :with => proc { |c| c.redirect_to special_login_path }
end

Obviously, this wouldn't work for an around filter.

Reported by Brennan Dunn · August 31st, 2008 @ 10:47 PM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Brennan Dunn
    Brennan Dunn

    Typo in documentation. SpecialController should extend ApplicationController (applies to ticket example, also).

    Revised patch attached.

    August 31st, 2008 @ 10:48 PM

  2. DHH
    DHH
    • State changed from new to wontfix

    When you want something special, you can just overwrite redirect_unless_logged_in in the SpecialController. It'll work by inheritance.

    September 10th, 2008 @ 05:50 AM