Skip to content

Instantly share code, notes, and snippets.

@willcosgrove
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willcosgrove/7965970a7b60d8bb4b71 to your computer and use it in GitHub Desktop.
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 ...
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
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