- Modify keywords in cities_controller.rb to include 'ai weather' - Update keywords in weather_arts_controller.rb to include 'ai weather' - Change keywords in application.html.erb to include 'ai weather' These changes enhance the search engine optimization (SEO) of the application by ensuring that relevant keywords are included in meta tags, improving visibility for users searching for AI weather-related content.
77 lines
2.3 KiB
Ruby
77 lines
2.3 KiB
Ruby
class CitiesController < ApplicationController
|
|
before_action :authenticate_user!, only: [ :generate_weather_art ]
|
|
before_action :require_admin, only: [ :generate_weather_art ]
|
|
|
|
def index
|
|
@regions = Region.order(:name)
|
|
@cities = City.includes(:country, country: :region).order(:name)
|
|
@latest_arts = WeatherArt.includes(:city, :image_attachment).latest(1)
|
|
|
|
if params[:query].present?
|
|
@cities = @cities.search_by_name(params[:query])
|
|
end
|
|
|
|
if params[:region]
|
|
@current_region = Region.friendly.find(params[:region])
|
|
@cities = @cities.by_region(@current_region.id) if @current_region
|
|
end
|
|
|
|
if params[:country]
|
|
@current_country = Country.friendly.find(params[:country])
|
|
@cities = @cities.by_country(@current_country.id) if @current_country
|
|
end
|
|
|
|
@cities = @cities.page(params[:page]).per(12)
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.turbo_stream {
|
|
render turbo_stream: turbo_stream.update("cities_results",
|
|
partial: "cities/results",
|
|
locals: { cities: @cities }
|
|
)
|
|
}
|
|
end
|
|
end
|
|
|
|
def show
|
|
@city = City.friendly.find(params[:id])
|
|
@arts = @city.weather_arts.order(weather_date: :desc).includes([ :image_attachment ])
|
|
ahoy.track "View City", {
|
|
city_id: @city.id,
|
|
name: @city.name,
|
|
event_type: "city_view"
|
|
}
|
|
|
|
set_meta_tags(
|
|
title: @city.name,
|
|
description: "Experience #{@city.name}'s weather through AI-generated art. Daily updates of weather conditions visualized through artificial intelligence.",
|
|
keywords: "#{@city.name}, #{@city.country.name}, ai art, ai weather, weather art, AI visualization",
|
|
og: {
|
|
image: @city.latest_weather_art&.image&.attached? ? url_for(@city.latest_weather_art.image) : nil
|
|
}
|
|
)
|
|
end
|
|
|
|
def generate_weather_art
|
|
@city = City.friendly.find(params[:id])
|
|
GenerateWeatherArtWorker.perform_async(@city.id)
|
|
|
|
respond_to do |format|
|
|
format.html do
|
|
flash[:notice] = "Weather art generation has been queued"
|
|
redirect_to @city
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def require_admin
|
|
unless current_user&.admin?
|
|
flash[:error] = "You are not authorized to perform this action"
|
|
redirect_to root_path
|
|
end
|
|
end
|
|
end
|