refactor: improve string representation for countries

- Update links in cities index to include country emoji
- Modify display in cities show view to use emoji and country name
- Clean up random scope method in weather_art model for consistency

These changes enhance the user interface presentation by making
country names visually enriched with emojis, improving the overall
user experience with clearer visual cues.
This commit is contained in:
songtianlun 2025-02-13 17:58:41 +08:00
parent eb16f5886d
commit ec96914067
3 changed files with 5 additions and 5 deletions

View File

@ -34,13 +34,13 @@ class WeatherArt < ApplicationRecord
scope :random, ->(limit = 3) {
if ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
# PostgreSQL 优化版本
order(Arel.sql('RANDOM()')).limit(limit)
order(Arel.sql("RANDOM()")).limit(limit)
elsif ActiveRecord::Base.connection.adapter_name.downcase == "mysql2"
# MySQL 优化版本
order(Arel.sql('RAND()')).limit(limit)
order(Arel.sql("RAND()")).limit(limit)
else
# SQLite 或其他数据库的通用版本
order(Arel.sql('RANDOM()')).limit(limit)
order(Arel.sql("RANDOM()")).limit(limit)
end
}

View File

@ -93,7 +93,7 @@
<div class="divider my-1"></div>
<% @current_region.countries.order(:name).each do |country| %>
<li>
<%= link_to country.name,
<%= link_to "#{country&.emoji + " " || ""}#{country.name}",
cities_path(region: @current_region.slug, country: country.slug),
class: "#{@current_country == country ? 'active' : ''}" %>
</li>

View File

@ -32,7 +32,7 @@
<div class="flex flex-wrap justify-center items-center gap-3">
<div class="badge badge-lg badge-primary gap-2">
<%= @city.country.name %>, <%= @city.region %>
<%= "#{@city&.country&.emoji + " " || ""}#{@city&.country&.name}" %>, <%= @city.region %>
</div>
<div class="badge badge-lg badge-secondary gap-2">
<%= @city.timezone.present? ? Time.current.in_time_zone(@city.timezone).strftime("%Y-%m-%d %H:%M") : "Timezone undefined" %>