userモデルの作成
rails g model user
# マイグレーションファイル class CreateUsers < ActiveRecord::Migration[6.0] def change create_table :users do |t| t.string :nickname, null: false t.string :password, null: false t.timestamps end end end
rails db:migrate
# userモデル class User < ApplicationRecord with_options presence: true do validates :nickname, length: { maximum: 20 }, uniqueness: true validates :password, length: { in: 6..20 } end has_one :score end
scoreモデルの作成
rails g model score
# マイグレーションファイル class CreateScores < ActiveRecord::Migration[6.0] def change create_table :scores do |t| t.references :user, null: false, foreign_key: true t.integer :score, null: false t.timestamps end end end
rails db:migrate
# scorerモデル class Score < ApplicationRecord with_options presence: true do validates :user_id validates :score end belongs_to :user end
gamesコントローラーの作成
rails g controller games
# gamesコントローラー class GamesController < ApplicationController def index end end
index.html.erbの作成
# app/views/games配下にindex.html.erbを作成 <h1>トップページ</h1>
ルーティングを設定
Rails.application.routes.draw do root to: 'games#index' resources :games, only: :index end
ここで、トップページが表示されるかローカルサーバーで確認しようとした
そのとき・・・
というエラーが発生!!!
「新規アプリの作成(1)」でスルーしたツケが早くも来てしまった、、、