today_ai_weather/app/controllers/rss_controller.rb
songtianlun 9ff27cbe4d fix: correct region and subregion retrieval
- Update region access to use country.region instead of city.region
- Update subregion access to use country.subregion instead of city.subregion

These changes ensure that the region and subregion are accurately retrieved based on the correct geographical hierarchy, improving the data integrity of the application.
2025-03-05 16:26:10 +08:00

48 lines
1.6 KiB
Ruby

class RssController < ApplicationController
include TagHelper
def feed
@weather_arts = WeatherArt.order(created_at: :desc).includes(:image_attachment, city: [ :country, :state ]).limit(20)
Rails.logger.info "RssController#feed - Format: #{request.format}"
respond_to do |format|
format.rss { render layout: false }
format.json { render json: generate_json_feed }
end
end
private
def generate_json_feed
{
version: "https://jsonfeed.org/version/1.1",
title: "Today AI Weather Art",
home_page_url: root_url,
feed_url: rss_feed_url(format: :json),
items: @weather_arts.map do |art|
{
id: city_weather_art_url(art.city, art),
url: city_weather_art_url(art.city, art),
title: "#{art.city.full_name} Weather Art",
content_html: "<p>#{art.description}</p>",
date_published: art.created_at.iso8601,
image: art.image.attached? ? rails_blob_url(art.webp_image.processed) : nil,
metadata: {
country: format_as_tag(art.city&.country&.name),
city: format_as_tag(art.city&.name),
state: format_as_tag(art.city&.state&.name),
region: format_as_tag(art.city&.country&.region&.name),
subregion: format_as_tag(art.city&.country&.subregion&.name),
description: art.description,
prompt: art.prompt,
date: art.weather_date&.strftime("%Y-%m-%d"),
dateYear: art.weather_date&.strftime("%Y"),
formattedDate: art.formatted_time(:all, true),
cityUrl: city_url(art.city)
}
}
end
}
end
end