songtianlun
8e8c60254f
- Implement CitiesController for listing and showing cities - Create City and WeatherArt models with associations - Add views for cities index and show, displaying weather arts - Include routes for cities and active storage for images - Update migrations for weather arts and seed data for testing This commit introduces a comprehensive cities feature that allows users to view cities along with their associated weather art. The implementation includes necessary database migrations, routes, and controller actions to support this new functionality.
60 lines
1.7 KiB
Ruby
60 lines
1.7 KiB
Ruby
# This file should ensure the existence of records required to run the application in every environment (production,
|
|
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
|
|
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
|
|
#
|
|
# Example:
|
|
#
|
|
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
|
|
# MovieGenre.find_or_create_by!(name: genre_name)
|
|
# end
|
|
|
|
User.create!(name: "Example User",
|
|
email: "example@example.com",
|
|
password: "foobar",
|
|
password_confirmation: "foobar",
|
|
admin: true,
|
|
activated: true,
|
|
activated_at: Time.zone.now)
|
|
|
|
9.times do |n|
|
|
name = Faker::Name.name
|
|
email = "example-#{n+1}@railstutorial.org"
|
|
password = "password"
|
|
User.create!(name: name,
|
|
email: email,
|
|
password: password,
|
|
password_confirmation: password,
|
|
activated: true,
|
|
activated_at: Time.zone.now)
|
|
end
|
|
|
|
City.create!(
|
|
name: "Guangzhou",
|
|
country: "China",
|
|
latitude: 23.125178,
|
|
longitude: 113.280637,
|
|
featured: true,
|
|
)
|
|
|
|
sample_art = WeatherArt.create!(
|
|
city_id: City.first.id,
|
|
weather_date: Time.zone.today,
|
|
description: "Sunny",
|
|
temperature: 21,
|
|
feeling_temp: 19,
|
|
humidity: 28,
|
|
wind_scale: 2,
|
|
wind_speed: 8,
|
|
precipitation: 0.0,
|
|
pressure: 1008,
|
|
visibility: 30,
|
|
cloud: 0,
|
|
prompt: "Artistic sunny weather in Guangzhou"
|
|
)
|
|
|
|
sample_art.image.attach(
|
|
io: File.open("db/seeds/images/sample_guangzhou_weather_art.png"),
|
|
filename: "sample_guangzhou_art.png",
|
|
content_type: "image/png"
|
|
)
|