Created
January 17, 2014 18:13
-
-
Save krisleech/8478579 to your computer and use it in GitHub Desktop.
view conditional with yield
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
class MyPresenter | |
def initialize(user) | |
@user = user | |
end | |
def admin_only(&block) | |
yield if user.admin? | |
end | |
end | |
# or | |
module MyHelper | |
def admin_only(&block) | |
yield if current_user.admin? | |
end | |
end |
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
- admin_only do | |
%p secret admin stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment