Skip to content

Instantly share code, notes, and snippets.

Created February 24, 2012 16:10
Show Gist options
  • Select an option

  • Save anonymous/1901805 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/1901805 to your computer and use it in GitHub Desktop.
Make filter DRY
# How can I move the filter into a helper and make the Model name dynamic?
#Page controller
before_filter :published_or_authenticated, :only => [:show]
def published_or_authenticated
@page = Page.find(params[:id])
if !user_signed_in? && @page.published == false
raise ActionController::RoutingError.new('Not Found')
end
end
#Post controller
before_filter :published_or_authenticated, :only => [:show]
def published_or_authenticated
@post = Post.find(params[:id])
if !user_signed_in? && @post.published == false
raise ActionController::RoutingError.new('Not Found')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment