today_ai_weather/app/models/weather_art.rb
songtianlun 8e8c60254f feat: add cities feature with weather arts
- Implement CitiesController for listing and showing cities
- Create City and WeatherArt models with associations
- Add views for cities index and show, displaying weather arts
- Include routes for cities and active storage for images
- Update migrations for weather arts and seed data for testing

This commit introduces a comprehensive cities feature that allows users to view cities along with their associated weather art. The implementation includes necessary database migrations, routes, and controller actions to support this new functionality.
2025-01-18 21:42:31 +08:00

13 lines
342 B
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class WeatherArt < ApplicationRecord
belongs_to :city
has_one_attached :image
scope :latest, -> { order(created_at: :desc) }
def image_url
# 这里实现获取图片URL的逻辑可以是AWS S3或其他存储服务
Rails.application.routes.url_helpers.rails_blob_path(image, only_path: true) if image.attached?
end
end