-
-
Save awesome/56677ba7bcfab364bc826024ab371e2f to your computer and use it in GitHub Desktop.
Passing arguments to an around_filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controller/articles_controller.rb | |
around_filter { |controller, action| controller.send(:add_published_scope, Article){ action.call } } | |
# app/controller/application_controller.rb | |
def add_published_scope(klass = nil, &block) | |
unless klass | |
klass = controller_name.classify.constantize | |
end | |
klass.with_scope(:find => klass.where("published_at <= ?", Time.zone.now)) do | |
yield | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment