From 5a3f8d2a6e9aab47b49064a548f7c898824de60a Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 10 Apr 2020 16:12:48 +0500 Subject: [PATCH] Add method ApplicationHelper#maybe_or_none --- app/helpers/application_helper.rb | 4 ++++ app/views/settings/people/show.html.erb | 24 ++++++------------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 43b0046..b5f35be 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -61,6 +61,10 @@ module ApplicationHelper end end + def maybe_or_none(cond) + cond ? yield : none + end + def bool_badge(value) if value tag.span class: 'badge badge-pill badge-success' do diff --git a/app/views/settings/people/show.html.erb b/app/views/settings/people/show.html.erb index 1d92247..b01208d 100644 --- a/app/views/settings/people/show.html.erb +++ b/app/views/settings/people/show.html.erb @@ -13,55 +13,43 @@
<%= Person.human_attribute_name :last_name %>
- <% if @account.person.last_name %> + <%= maybe_or_none @account.person.last_name.present? do %> <%= truncate @account.person.last_name %> - <% else %> - <%= none %> <% end %>
<%= Person.human_attribute_name :first_name %>
- <% if @account.person.first_name.present? %> + <%= maybe_or_none @account.person.first_name.present? do %> <%= truncate @account.person.first_name %> - <% else %> - <%= none %> <% end %>
<%= Person.human_attribute_name :middle_name %>
- <% if @account.person.middle_name.present? %> + <%= maybe_or_none @account.person.middle_name.present? do %> <%= truncate @account.person.middle_name %> - <% else %> - <%= none %> <% end %>
<%= Person.human_attribute_name :sex %>
- <% if @account.person.sex.present? %> + <%= maybe_or_none @account.person.sex.present? do %> <%= translate_enum :sex, @account.person.sex %> - <% else %> - <%= none %> <% end %>
<%= Person.human_attribute_name :date_of_birth %>
- <% if @account.person.date_of_birth.present? %> + <%= maybe_or_none @account.person.date_of_birth.present? do %> <%= localize @account.person.date_of_birth %> - <% else %> - <%= none %> <% end %>
<%= Person.human_attribute_name :place_of_birth %>
- <% if @account.person.place_of_birth.present? %> + <%= maybe_or_none @account.person.place_of_birth.present? do %> <%= truncate @account.person.place_of_birth %> - <% else %> - <%= none %> <% end %>