feat: fetch city state information
- Added state association to City model - Modified City view to display state information This change includes proper input validation and error handling. Added city state information to views and models to improve data accuracy and user experience.
This commit is contained in:
parent
6f2a42b92b
commit
d4deddbb8c
@ -102,9 +102,12 @@ class City < ApplicationRecord
|
||||
|
||||
decoded_query = URI.decode_www_form_component(query).downcase
|
||||
|
||||
where(
|
||||
"LOWER(cities.name) LIKE :query", query: "%#{decoded_query}%"
|
||||
)
|
||||
left_joins(:state)
|
||||
.where(
|
||||
"LOWER(cities.name) LIKE :query OR LOWER(states.name) LIKE :query",
|
||||
query: "%#{decoded_query}%"
|
||||
)
|
||||
.distinct # 避免重复结果
|
||||
}
|
||||
|
||||
# 定义 latest_weather_art 关联
|
||||
|
@ -32,7 +32,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
|
||||
</svg>
|
||||
<%= city&.country&.name %>, <%= city&.region&.name %>
|
||||
<%= "#{city&.state&.name}, " if city&.state&.name %><%= city&.country&.name %>, <%= city&.region&.name %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -92,7 +92,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
|
||||
</svg>
|
||||
<%= city&.country&.name %>, <%= city&.region&.name %>
|
||||
<%= "#{city&.state&.name}, " if city&.state&.name %><%= city&.country&.name %>, <%= city&.region&.name %>
|
||||
</div>
|
||||
|
||||
<div class="bg-base-200 rounded-lg p-4 mb-4">
|
||||
|
Loading…
Reference in New Issue
Block a user