Skip to content

Commit

Permalink
Pass the status symbol to the method not the status value
Browse files Browse the repository at this point in the history
  • Loading branch information
kasugaijin committed Jun 26, 2024
1 parent 7045fa7 commit b14aab0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class ApplicationRecord < ActiveRecord::Base
primary_abstract_class

# This method is used to translate the enum values for i18n.
def human_enum_name(enum_name, enum_value)
I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{enum_name}.#{enum_value}")
def human_enum_name(enum)
enum_i18n_key = enum.to_s
value = send(enum)
I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{enum_i18n_key}.#{value}")
end
end
2 changes: 1 addition & 1 deletion app/views/organizations/adoptable_pets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<% if AdopterApplication.adoption_exists?(current_user.adopter_foster_account&.id, @pet.id) %>
<div class='d-flex align-items-center mt-3'>
<h4 class="me-2 mb-0">
<%= "Application Status: #{@adoption_application.human_enum_name('status', @adoption_application.status) || t('.status.default')}" %>
<%= "Application Status: #{@adoption_application.human_enum_name(:status) || t('.status.default')}" %>
</h4>
<% if %w[under_review adoption_pending].include?(@adoption_application.status) %>
<%= image_tag('pause.png', height: '21') %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<li class="list-group-item d-flex flex-wrap justify-content-between text-secondary">
<div class="me-1 fw-semibold"><%= t("views.dashboard.applications.status")%>:</div>
<div>
<%= application.human_enum_name('status', application.status) %>
<%= application.human_enum_name(:status) %>
</div>
</li>
<li class="list-group-item d-flex justify-content-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<%= l app.created_at.to_date, format: :long %>
</td>
<td>
<%= app.human_enum_name('status', app.status) %>
<%= app.human_enum_name(:status) %>
</td>
<td>
<% if app.status == 'withdrawn' %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="dropdown">
<button class="btn dropdown-toggle <%= application_status_classes(app)%>" data-bs-toggle="dropdown" aria-expanded="false">
<%= app.human_enum_name('status', app.status) %>
<%= app.human_enum_name(:status) %>
</button>
<ul class="dropdown-menu">
<% AdopterApplication.statuses.keys.each do |status| %>
Expand Down

0 comments on commit b14aab0

Please sign in to comment.