today_ai_weather/db/seeds.rb

60 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2024-12-29 17:12:54 +08:00
# 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"
)