Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created January 17, 2014 18:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/8478579 to your computer and use it in GitHub Desktop.
Save krisleech/8478579 to your computer and use it in GitHub Desktop.
view conditional with yield
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
- 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