Last active
August 29, 2015 14:18
-
-
Save willcosgrove/7965970a7b60d8bb4b71 to your computer and use it in GitHub Desktop.
blank_or - View helper to render blank text if a value is blank, or ...
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
def blank_or(attribute, blank_text: "N/A", blank_test: :blank?) | |
if attribute.send(blank_test) | |
return blank_text | |
else | |
return yield(attribute) if block_given? | |
return attribute | |
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
table.table.table-striped | |
thead | |
tr | |
th Name | |
th Email | |
th Last Logged In At | |
tbody | |
- @user.each do |user| | |
tr | |
td= user.name | |
td= user.email | |
td= blank_or(user.last_logged_in_at) { |time| time.stamp("1:32PM 12/31/99") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment