today_ai_weather/app/models/city.rb
songtianlun d570f43f95 feat: add font styling and enhance city views
- Import Playfair Display and Raleway fonts for better typography
- Add a method to `City` model for fetching the latest weather art
- Revamp city index and show pages for improved layout and usability
- Update styles in the layout and main pages to enhance user experience

These changes promote visual consistency and enhance user interaction within the platform, providing a more engaging experience.
2025-01-20 18:02:28 +08:00

28 lines
744 B
Ruby

class City < ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged
has_many :weather_arts, dependent: :destroy
validates :name, presence: true
validates :latitude, presence: true
validates :longitude, presence: true
def should_generate_new_friendly_id?
name_changed? || super
end
def self.ransackable_associations(auth_object = nil)
[ "weather_arts" ]
end
def self.ransackable_attributes(auth_object = nil)
["active", "country", "created_at", "id", "id_value", "last_image_generation", "last_weather_fetch", "latitude", "longitude", "name", "priority", "region", "slug", "timezone", "updated_at"]
end
def latest_weather_art
weather_arts.order(weather_date: :desc).first
end
end