Created
February 24, 2012 16:10
-
-
Save anonymous/1901805 to your computer and use it in GitHub Desktop.
Make filter DRY
This file contains hidden or 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
| # 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