From ec9691406703025d82e780d053f4dab9faf03dd6 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Thu, 13 Feb 2025 17:58:41 +0800 Subject: [PATCH] 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. --- app/models/weather_art.rb | 6 +++--- app/views/cities/index.html.erb | 2 +- app/views/cities/show.html.erb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/weather_art.rb b/app/models/weather_art.rb index 175b7c4..f624037 100644 --- a/app/models/weather_art.rb +++ b/app/models/weather_art.rb @@ -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 } diff --git a/app/views/cities/index.html.erb b/app/views/cities/index.html.erb index 425138f..3706f00 100644 --- a/app/views/cities/index.html.erb +++ b/app/views/cities/index.html.erb @@ -93,7 +93,7 @@
<% @current_region.countries.order(:name).each do |country| %>
  • - <%= link_to country.name, + <%= link_to "#{country&.emoji + " " || ""}#{country.name}", cities_path(region: @current_region.slug, country: country.slug), class: "#{@current_country == country ? 'active' : ''}" %>
  • diff --git a/app/views/cities/show.html.erb b/app/views/cities/show.html.erb index b0d504b..bd87b53 100644 --- a/app/views/cities/show.html.erb +++ b/app/views/cities/show.html.erb @@ -32,7 +32,7 @@
    - <%= @city.country.name %>, <%= @city.region %> + <%= "#{@city&.country&.emoji + " " || ""}#{@city&.country&.name}" %>, <%= @city.region %>
    <%= @city.timezone.present? ? Time.current.in_time_zone(@city.timezone).strftime("%Y-%m-%d %H:%M") : "Timezone undefined" %>