fix: correct state name presence check
Some checks failed
Docker Dev / docker (push) Has been cancelled
CI / scan_ruby (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
Docker Main / docker (push) Has been cancelled

- Update condition to check for state presence instead of name
- Ensure proper rendering of state badge in city and weather art views

This change improves the logic for displaying the state badge by
checking for the presence of the state object directly, which
prevents potential errors when the state name is not set. It
ensures that the badge is displayed correctly when a state is
associated with a city or weather art.
This commit is contained in:
songtianlun 2025-04-26 00:29:33 +08:00
parent 639c36200b
commit 0bca23ff77
2 changed files with 2 additions and 2 deletions

View File

@ -45,7 +45,7 @@
<%= link_to cities_path(country: @city.country, state: @city.state, region: @city.country.region), class: "badge badge-lg badge-secondary hover:badge-outline transition-all duration-200" do %>
<%= @city.state.name %>
<% end %>
<% elsif @city.state.name.present? %>
<% elsif @city.state.present? %>
<div class="badge badge-lg badge-secondary">
<%= @city&.state&.name %>
</div>

View File

@ -37,7 +37,7 @@
<%= link_to cities_path(country: @weather_art.city.country, state: @weather_art.city.state, region: @weather_art.city.country.region), class: "badge badge-lg badge-secondary hover:badge-outline transition-all duration-200" do %>
<%= @weather_art.city.state.name %>
<% end %>
<% elsif @weather_art.city.state.name.present? %>
<% elsif @weather_art.city.state.present? %>
<div class="badge badge-lg badge-secondary">
<%= @weather_art&.city&.state&.name %>
</div>