- Add slug column to weather_arts for friendly URLs. - Update weather arts retrieval in the controller to use slug. - Implement region and country filtering in cities index view. - Optimize city queries with scopes for active status and region/country. - Improve UI layout and design for the cities index page. These changes allow better user experience by enabling cleaner URLs for weather arts and facilitating efficient filtering of cities based on selected regions and countries.
27 lines
806 B
Ruby
27 lines
806 B
Ruby
class WeatherArt < ApplicationRecord
|
|
extend FriendlyId
|
|
friendly_id :weather_date, use: :slugged
|
|
|
|
belongs_to :city
|
|
has_one_attached :image
|
|
|
|
validates :weather_date, presence: true
|
|
validates :city_id, presence: true
|
|
|
|
def should_generate_new_friendly_id?
|
|
weather_date_changed? || city_id_changed? || super
|
|
end
|
|
|
|
def to_s
|
|
"#{city.name} - #{weather_date.strftime('%Y-%m-%d')}"
|
|
end
|
|
|
|
def self.ransackable_associations(auth_object = nil)
|
|
[ "city", "image_attachment", "image_blob" ]
|
|
end
|
|
|
|
def self.ransackable_attributes(auth_object = nil)
|
|
[ "city_id", "cloud", "created_at", "description", "feeling_temp", "humidity", "id", "id_value", "precipitation", "pressure", "prompt", "temperature", "updated_at", "visibility", "weather_date", "wind_scale", "wind_speed" ]
|
|
end
|
|
end
|