today_ai_weather/app/models/weather_art.rb

13 lines
342 B
Ruby
Raw Normal View History

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