This project is archived and is in readonly mode.

#946 ✓wontfix
Brennan Dunn

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

Reported by Brennan Dunn | August 31st, 2008 @ 10:47 PM | in 2.x

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.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages