1
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?

【初心者プログラマー】SaveData開発日記 # ゲームデータを登録してみよう コンソール使い回

Last updated at Posted at 2026-01-19

前回のあらすじ :ゲームを登録する画面を作った


今回は実際にゲームのデータを登録して
反映されているかを見ていきます。

こ、こいつ脳内(データベース)に直接...?!!!!作業します

脳内に直接猫.png

Railsコンソールに直接登録してみる

年表部分にデータがちゃんと表示されるかどうかを確認するために
先に何件か取り込んでみます。

railsコンソールに起きて〜って言うコマンド
docker compose exec web rails console

ユーザーを読み込む
myapp(dev)> u = User.first
myapp(dev)> 
  User Load (1.0ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1  [["LIMIT", 1]]
そしたらこんなのが出てくるからデータを打っていく
myapp(dev)*


myapp(dev)* u.games.create!(
myapp(dev)*   title: "ロマンシング サガ3",
myapp(dev)*   hardware: "SFC",
myapp(dev)*   genre: "RPG",
myapp(dev)*   difficulty: 4,
myapp(dev)*   fun: 5,
myapp(dev)*   played_year: 1995,
myapp(dev)*   played_age: 10,
myapp(dev)*   memo: "音楽が抒情的で、年を越えても忘れられない一本"
myapp(dev)> )
myapp(dev)> 
myapp(dev)* u.games.create!(
myapp(dev)*   title: "クロノ・トリガー",
myapp(dev)*   hardware: "SFC",
myapp(dev)*   genre: "RPG",
myapp(dev)*   difficulty: 3,
myapp(dev)*   fun: 5,
myapp(dev)*   played_year: 1996,
myapp(dev)*   played_age: 11,
myapp(dev)*   memo: "時間を旅するという概念を初めて知った"
myapp(dev)> )

するとこんなのが出てくる
スクリーンショット 2026-01-19 9.29.48.png

打ったらexitと入力しコンソールから抜ける
myapp(dev)> exit

念の為しっかり入ってるか確認

# ユーザーの中でもID6の人のデータを確認しますー
myapp(dev)> @user = User.find(6)

myapp(dev)> 
  User Load (0.8ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 6], ["LIMIT", 1]]
=> 
#<User id: 6, email: [FILTERED], name: "uni", birthday: "2012-01-03", gender: true, crypted_password: nil, created_at: "2026-01-17 04:17:02.646712000 +0000", updated_at: "2026-01-...
myapp(dev)> @games = @user.games
myapp(dev)>               .where.not(played_year: nil)
myapp(dev)>               .where.not(title: "")
myapp(dev)>               .order(:played_year)
myapp(dev)> 

  Game Load (0.6ms)  SELECT "games".* FROM "games" WHERE "games"."user_id" = $1 AND "games"."played_year" IS NOT NULL AND "games"."title" != $2 /* loading for pp */ ORDER BY "games"."played_year" ASC LIMIT $3  [["user_id", 6], ["title", ""], ["LIMIT", 11]]
=> 
myapp(dev)> @games.pluck(:title, :played_year)

  Game Pluck (0.7ms)  SELECT "games"."title", "games"."played_year" FROM "games" WHERE "games"."user_id" = $1 AND "games"."played_year" IS NOT NULL AND "games"."title" != $2 ORDER BY "games"."played_year" ASC  [["user_id", 6], ["title", ""]]
=> [["ロマンシング サガ3", 1995], ["クロノ・トリガー", 1996], ["ファイナルファンタジーVII", 1997], ["ダークソウル", 2011], ["SEKIRO", 2019]]

しっかり読まれてますね。

年表画面に反映されてるか確認

スクリーンショット 2026-01-19 12.06.54.png

しっかり出てますね。
UIに関してはまだまだ改善の余地有りなので
少しずつちゃっぴいちゃんと画面遷移図を参考に
組み立てていきます。

次回はゲーム登録画面から直接反映されているかを確認していきます。
ご覧いただきありがとうございました。

1
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
1
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?