Skip to content

Instantly share code, notes, and snippets.

@yurikoval
Created September 7, 2012 05:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yurikoval/3663539 to your computer and use it in GitHub Desktop.
Save yurikoval/3663539 to your computer and use it in GitHub Desktop.
Passing arguments to an around_filter
# 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