Skip to content

Commit 1264dd2

Browse files
committed
add user model & db data
1 parent a6f193f commit 1264dd2

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ gem 'puma', '~> 3.11'
1414
# Use Redis adapter to run Action Cable in production
1515
# gem 'redis', '~> 4.0'
1616
# Use ActiveModel has_secure_password
17-
# gem 'bcrypt', '~> 3.1.7'
17+
gem 'bcrypt', '~> 3.1.7'
1818

1919
# Use ActiveStorage variant
2020
# gem 'mini_magick', '~> 4.8'

app/models/user.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class User < ApplicationRecord
2+
has_secure_password
3+
4+
validates :name, presence: true
5+
validates :email, presence: true
6+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CreateUsers < ActiveRecord::Migration[5.2]
2+
def change
3+
create_table :users do |t|
4+
t.string :password_digest
5+
t.string :name
6+
t.string :email
7+
8+
t.timestamps
9+
end
10+
end
11+
end

db/schema.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# Note that this schema.rb definition is the authoritative source for your
6+
# database schema. If you need to create the application database on another
7+
# system, you should be using db:schema:load, not running all the migrations
8+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9+
# you'll amass, the slower it'll run and the greater likelihood for issues).
10+
#
11+
# It's strongly recommended that you check this file into your version control system.
12+
13+
ActiveRecord::Schema.define(version: 2019_03_22_143614) do
14+
15+
create_table "users", force: :cascade do |t|
16+
t.string "password_digest"
17+
t.string "name"
18+
t.string "email"
19+
t.datetime "created_at", null: false
20+
t.datetime "updated_at", null: false
21+
end
22+
23+
end

db/seeds.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# This file should contain all the record creation needed to seed the database with its default values.
2-
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3-
#
4-
# Examples:
5-
#
6-
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7-
# Character.create(name: 'Luke', movie: movies.first)
1+
User.destroy_all
2+
3+
User.create!({
4+
name: 'daisuke.takayama',
5+
6+
password: 'test123',
7+
password_confirmation: 'test123'
8+
})

0 commit comments

Comments
 (0)