0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

seed値入力

Last updated at Posted at 2021-07-02
100.times do |n|
  email = Faker::Internet.email
  password = 'q12345'
  User.create!(email: email,
               password: password,
               password_confirmation: password,
               )
end
require 'faker'

100.times do |n|
  family_name = Gimei.last.kanji
  last_name = Gimei.first.kanji
  family_name_prono = Gimei.last.katakana
  last_name_prono = Gimei.first.katakana
  postal_code = Faker::Lorem.characters(number: 3, min_numeric: 3) + '-' + Faker::Lorem.characters(number: 4, min_numeric: 4) 
  prefecture_id = Faker::Number.between(from: 2, to: 48)
  address = Gimei.address.city.kanji
  street = Gimei.address.town.kanji + Faker::Lorem.characters(number: 1, min_numeric: 1) + '-' + Faker::Lorem.characters(number: 2, min_numeric: 2) 
  phone_number = '0'+ Faker::Lorem.characters(number: 10, min_numeric: 10)
  sex = Faker::Number.between(from: 1, to: 2)
  body_weight = Faker::Number.between(from: 45, to: 115)
  tall = Faker::Number.between(from: 135, to: 205)
  birthday = Faker::Date.between(from: '1959-1-1', to: '2001-12-31')
  Profile.create!(family_name: family_name,
               first_name: last_name,
               family_name_prono: family_name_prono,
               first_name_prono: last_name_prono,
               postal_code: postal_code,
               prefecture_id: prefecture_id,
               address: address,
               street: street,
               phone_number: phone_number,
               sex: sex,
               body_weight: body_weight,
               tall: tall,
               birthday: birthday,
               user_id: User.find(n+1).id,
               )
end

20210703-214143.png

上記csvをデータインストール

require "csv"

CSV.foreach('db/本表-表1.csv', headers: true)  do |row|
  FoodStuff.create(
  food_stuff: row['food_name'],
  calorie: row['calorie'],
  protein: row['protein'],
  carbohydrate: row['carbohydrate'],
  sugar_content: row['sugar_content'],
  salt: row['salt'],
  lipid: row['lopid'],
  fiber: row['fiber'],
)
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?