feat: update city display and database schema

- Change city name display to localized name in both index and show views
- Modify schema to use bigint for certain foreign keys
- Correct country codes in seeds for accurate data representation

These changes improve the handling of city names, ensuring they are displayed in the appropriate localized format and ensuring well-typed foreign key relationships in the schema.
This commit is contained in:
songtianlun 2025-01-21 21:29:26 +08:00
parent ebaf7a3f34
commit c11d10c86a
26 changed files with 51 additions and 52 deletions

View File

@ -19,7 +19,7 @@
<% end %>
<div class="card-body relative">
<h2 class="card-title font-display text-2xl"><%= city.name %></h2>
<h2 class="card-title font-display text-2xl"><%= city.localized_name %></h2>
<div class="text-base-content/70">
<p>Lat: <%= city.latitude %></p>
<p>Long: <%= city.longitude %></p>

View File

@ -17,7 +17,7 @@
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
<% end %>
<h1 class="text-4xl md:text-5xl font-display font-bold"><%= @city.name %></h1>
<h1 class="text-4xl md:text-5xl font-display font-bold"><%= @city.localized_name %></h1>
</div>
<div class="stats bg-base-100/80 backdrop-blur-sm shadow">

13
db/schema.rb generated
View File

@ -11,13 +11,16 @@
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_01_21_020653) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace"
t.text "body"
t.string "resource_type"
t.integer "resource_id"
t.bigint "resource_id"
t.string "author_type"
t.integer "author_id"
t.bigint "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author"
@ -77,7 +80,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_21_020653) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.integer "country_id", null: false
t.bigint "country_id", null: false
t.index ["country_id"], name: "index_cities_on_country_id"
t.index ["slug"], name: "index_cities_on_slug", unique: true
end
@ -86,7 +89,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_21_020653) do
t.string "name"
t.string "code"
t.string "slug"
t.integer "region_id", null: false
t.bigint "region_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["code"], name: "index_countries_on_code", unique: true
@ -116,7 +119,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_21_020653) do
end
create_table "weather_arts", force: :cascade do |t|
t.integer "city_id", null: false
t.bigint "city_id", null: false
t.date "weather_date"
t.string "description"
t.decimal "temperature"

View File

@ -70,7 +70,6 @@ regions = Region.create!([
}
])
asia = Region.find_by(code: 'AS')
south_asia = Region.find_by(code: 'SA')
africa = Region.find_by(code: 'AF')
europe = Region.find_by(code: 'EU')
north_america = Region.find_by(code: 'NAM')
@ -87,9 +86,9 @@ Country.create!([
{ name: 'Hong Kong', code: 'HK', region: asia },
# South Asia
{ name: 'India', code: 'IN', region: south_asia },
{ name: 'Pakistan', code: 'PK', region: south_asia },
{ name: 'Bangladesh', code: 'BD', region: south_asia },
{ name: 'India', code: 'IN', region: asia },
{ name: 'Pakistan', code: 'PK', region: asia },
{ name: 'Bangladesh', code: 'BD', region: asia },
# Southeast Asia
{ name: 'Indonesia', code: 'ID', region: asia },
@ -97,7 +96,6 @@ Country.create!([
{ name: 'Thailand', code: 'TH', region: asia },
{ name: 'Myanmar', code: 'MM', region: asia },
{ name: 'Singapore', code: 'SG', region: asia },
{ name: 'Bangladesh', code: 'BD', region: asia },
# Middle East
{ name: 'Turkey', code: 'TR', region: asia },
@ -115,7 +113,6 @@ Country.create!([
{ name: 'Angola', code: 'AO', region: africa },
{ name: 'Mali', code: 'ML', region: africa },
{ name: 'Ivory Coast', code: 'CI', region: africa },
{ name: 'Egypt', code: 'EGY', region: africa },
# Europe
{ name: 'Russia', code: 'RU', region: europe },
@ -133,7 +130,6 @@ Country.create!([
{ name: 'Peru', code: 'PE', region: south_america },
{ name: 'Colombia', code: 'CO', region: south_america },
{ name: 'Chile', code: 'CL', region: south_america },
{ name: 'Brazil', code: 'BZ', region: south_america },
# Oceania
{ name: 'Australia', code: 'AU', region: oceania }
@ -144,7 +140,7 @@ Dir[Rails.root.join('db/seeds/cities/*.rb')].sort.each do |file|
require file
end
china = Country.find_by(code: 'CHN')
china = Country.find_by(code: 'CN')
guangzhou = City.create!(
name: 'Guangzhou',
latitude: 23.1291,

View File

@ -1,4 +1,4 @@
brazil = Country.find_by code: 'BZ'
brazil = Country.find_by code: 'BR'
City.create!([
{

View File

@ -1,4 +1,4 @@
egypt = Country.find_by code: 'EGY'
egypt = Country.find_by code: 'EG'
City.create!([
{

View File

@ -1,4 +1,4 @@
japan = Country.find_by 1
japan = Country.find_by code: 'JP'
City.create!([
{

View File

@ -1,4 +1,4 @@
mexico = Country.find_by 1
mexico = Country.find_by code: 'MX'
City.create!([
{

View File

@ -1,4 +1,4 @@
nigeria = Country.find_by 1
nigeria = Country.find_by code: 'NG'
City.create!([
{

View File

@ -1,4 +1,4 @@
pakistan = Country.find_by 1
pakistan = Country.find_by code: 'PK'
City.create!([
{

View File

@ -1,4 +1,4 @@
russia = Country.find_by 1
russia = Country.find_by code: 'RU'
City.create!([
{

View File

@ -1,4 +1,4 @@
saudi_arabia = Country.find_by 1
saudi_arabia = Country.find_by code: 'CA'
City.create!([
{

View File

@ -1,4 +1,4 @@
singapore = Country.find_by 1
singapore = Country.find_by code: 'SG'
City.create!([
{

View File

@ -1,4 +1,4 @@
south_korea = Country.find_by 1
south_korea = Country.find_by code: 'KR'
City.create!([
{

View File

@ -1,4 +1,4 @@
thailand = Country.find_by 1
thailand = Country.find_by code: 'TH'
City.create!([
{

View File

@ -1,4 +1,4 @@
turkey = Country.find_by 1
turkey = Country.find_by code: 'TR'
City.create!([
{

View File

@ -1,4 +1,4 @@
uk = Country.find_by 1
uk = Country.find_by code: 'GB'
City.create!([
{

View File

@ -1,4 +1,4 @@
usa = Country.find_by 1
usa = Country.find_by code: 'US'
City.create!([
{

View File

@ -1,4 +1,4 @@
vietnam = Country.find_by 1
vietnam = Country.find_by code: 'VN'
City.create!([
{