This project is archived and is in readonly mode.
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
-
Brennan Dunn August 31st, 2008 @ 10:48 PM
Typo in documentation. SpecialController should extend ApplicationController (applies to ticket example, also).
Revised patch attached.
-
DHH September 10th, 2008 @ 05:50 AM
- 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.
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>