Skip to content

Instantly share code, notes, and snippets.

@radar
Forked from anonymous/filter.rb
Created February 24, 2012 16:27
Show Gist options
  • Select an option

  • Save radar/1901873 to your computer and use it in GitHub Desktop.

Select an option

Save radar/1901873 to your computer and use it in GitHub Desktop.
Make filter DRY
def published_or_authenticated
scope = controller.name.gsub(/Controller$/, '').singularize.constantize.scoped
scope = user_signed_in? ? scope : scope.published
@page = scope.find(params[:id])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment