today_ai_weather/app/models/city.rb
songtianlun e5743a5e3f feat: add friendly_id for cities and weather arts
- Integrate 'friendly_id' gem for sluggable functionality in City model
- Create ActiveAdmin resources for managing cities and weather arts
- Implement controller logic for cities
- Add database migrations for cities and weather arts creation
- Seed database with sample data for testing
- Create initial test cases for controllers and models

This commit enhances the application's URL handling by allowing friendly URLs for cities and weather arts. The addition of ActiveAdmin resources facilitates easier management through a web interface.
2025-01-19 12:21:00 +08:00

24 lines
662 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
end