1
0
Fork 0

Add method ApplicationHelper#maybe_or_none

This commit is contained in:
Alex Kotov 2020-04-10 16:12:48 +05:00
parent ecbcd29338
commit 5a3f8d2a6e
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 10 additions and 18 deletions

View File

@ -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

View File

@ -13,55 +13,43 @@
<dl>
<dt><%= Person.human_attribute_name :last_name %></dt>
<dd>
<% if @account.person.last_name %>
<%= maybe_or_none @account.person.last_name.present? do %>
<%= truncate @account.person.last_name %>
<% else %>
<%= none %>
<% end %>
</dd>
<dt><%= Person.human_attribute_name :first_name %></dt>
<dd>
<% if @account.person.first_name.present? %>
<%= maybe_or_none @account.person.first_name.present? do %>
<%= truncate @account.person.first_name %>
<% else %>
<%= none %>
<% end %>
</dd>
<dt><%= Person.human_attribute_name :middle_name %></dt>
<dd>
<% if @account.person.middle_name.present? %>
<%= maybe_or_none @account.person.middle_name.present? do %>
<%= truncate @account.person.middle_name %>
<% else %>
<%= none %>
<% end %>
</dd>
<dt><%= Person.human_attribute_name :sex %></dt>
<dd>
<% if @account.person.sex.present? %>
<%= maybe_or_none @account.person.sex.present? do %>
<%= translate_enum :sex, @account.person.sex %>
<% else %>
<%= none %>
<% end %>
</dd>
<dt><%= Person.human_attribute_name :date_of_birth %></dt>
<dd>
<% 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 %>
</dd>
<dt><%= Person.human_attribute_name :place_of_birth %></dt>
<dd>
<% 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 %>
</dd>
</dl>