From 3db59dee2f401a1515a81631cce137f6bf49d7e8 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 14 Aug 2019 17:14:05 +0500 Subject: [PATCH] Add helper method RegionalOfficesHelper#regional_office_link_or_none --- app/helpers/regional_offices_helper.rb | 14 ++++++++++++++ app/views/staffs/people/show.html.erb | 11 +---------- 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 app/helpers/regional_offices_helper.rb diff --git a/app/helpers/regional_offices_helper.rb b/app/helpers/regional_offices_helper.rb new file mode 100644 index 0000000..8567902 --- /dev/null +++ b/app/helpers/regional_offices_helper.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module RegionalOfficesHelper + def regional_office_link_or_none(regional_office) + if regional_office.nil? + translate :none + elsif policy(regional_office.federal_subject).show? + link_to regional_office.federal_subject.display_name, + regional_office.federal_subject + else + regional_office.federal_subject.display_name + end + end +end diff --git a/app/views/staffs/people/show.html.erb b/app/views/staffs/people/show.html.erb index 9a2453e..18ab878 100644 --- a/app/views/staffs/people/show.html.erb +++ b/app/views/staffs/people/show.html.erb @@ -22,16 +22,7 @@
<%= staff_account_link_or_none @person.account %>
<%= Person.human_attribute_name :current_regional_office %>
-
- <% if @person.current_regional_office %> - <%= link_to( - @person.current_regional_office.federal_subject.display_name, - @person.current_regional_office.federal_subject, - ) %> - <% else %> - <%= translate :none %> - <% end %> -
+
<%= regional_office_link_or_none @person.current_regional_office %>
<%= Person.human_attribute_name :last_name %>
<%= truncate @person.last_name %>