diff --git a/app/controllers/arts_controller.rb b/app/controllers/arts_controller.rb index 07fabb9..b70273a 100644 --- a/app/controllers/arts_controller.rb +++ b/app/controllers/arts_controller.rb @@ -1,8 +1,21 @@ class ArtsController < ApplicationController def index - @weather_arts = WeatherArt.includes(:city, city: [ :country, { country: :region } ]) - .order(created_at: :desc) - .page(params[:page]) - .per(2) + @regions = Region.all + @current_region = Region.find(params[:region]) if params[:region].present? + + @weather_arts = WeatherArt.includes(city: [:country, { country: :region }]) + + if @current_region + @weather_arts = @weather_arts.joins(city: :country) + .where(countries: { region_id: @current_region.id }) + end + + @weather_arts = if params[:sort] == 'oldest' + @weather_arts.order(created_at: :asc) + else + @weather_arts.order(created_at: :desc) + end + + @weather_arts = @weather_arts.page(params[:page]).per(10) end end diff --git a/app/views/arts/index.html.erb b/app/views/arts/index.html.erb index c9eb43b..ddb77f4 100644 --- a/app/views/arts/index.html.erb +++ b/app/views/arts/index.html.erb @@ -1,66 +1,167 @@
- Explore our collection of AI-generated weather art from cities around the world -
+ + <% featured_art = @weather_arts.first %> ++ Discover AI-generated weather art from cities around the world +
+ + + <% if featured_art %> +- <%= art.weather_date.strftime("%B %d, %Y") %> -
-- <%= art.temperature %>°C, <%= art.description %> -
+ + + + ++ <%= art.city.country.name %> +
+- <%= art.city.country.name %> + <%= art.weather_date.strftime("%B %d, %Y") %>