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