質問編集履歴
2
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,4 +17,75 @@
|
|
17
17
|
|
18
18
|
cloud9
|
19
19
|
SQLite3
|
20
|
-
Rails
|
20
|
+
Rails
|
21
|
+
|
22
|
+
**app/controllers/users_controller.rb**
|
23
|
+
```
|
24
|
+
class UsersController < ApplicationController
|
25
|
+
|
26
|
+
def show
|
27
|
+
@user = User.find(params[:id])
|
28
|
+
end
|
29
|
+
|
30
|
+
def new
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
**app/models/user.rb**
|
37
|
+
```
|
38
|
+
class User < ApplicationRecord
|
39
|
+
before_save { self.email = email.downcase! }
|
40
|
+
validates :name, presence: true, length: { maximum: 50 }
|
41
|
+
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i
|
42
|
+
validates :email, presence: true, length: { maximum: 255 },
|
43
|
+
format: { with: VALID_EMAIL_REGEX },
|
44
|
+
uniqueness: { case_sensitive: false }
|
45
|
+
has_secure_password
|
46
|
+
validates :password, presence: true, length: { minimum: 6 }
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
**db/migrate/20210209213647_create_users**
|
51
|
+
```
|
52
|
+
class CreateUsers < ActiveRecord::Migration[5.1]
|
53
|
+
def change
|
54
|
+
create_table :users do |t|
|
55
|
+
t.string :name
|
56
|
+
t.string :email
|
57
|
+
|
58
|
+
t.timestamps
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
**db/migrate/20210210225051_add_index_to_users_email**
|
64
|
+
```ここに言語を入力
|
65
|
+
class AddIndexToUsersEmail < ActiveRecord::Migration[5.1]
|
66
|
+
def change
|
67
|
+
add_index :users, :email, unique: true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
71
|
+
**db/migrate/20210210233322_add_password_digest_to_users**
|
72
|
+
```ここに言語を入力
|
73
|
+
class AddPasswordDigestToUsers < ActiveRecord::Migration[5.1]
|
74
|
+
def change
|
75
|
+
add_column :users, :password_digest, :string
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
**helpers/users_helper.rb**
|
81
|
+
```
|
82
|
+
module UsersHelper
|
83
|
+
|
84
|
+
# Gravatar読み込み
|
85
|
+
def gravatar_for(user)
|
86
|
+
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
|
87
|
+
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
|
88
|
+
image_tag(gravatar_url, alt: user.name, class: "gravatar")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
```
|
1
詳しい状況を追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
SQLiteで一部カラムにデータを保存できません。
|
5
5
|
エラーもなく保存が完了したと思い見にいくとそこのカラムの値だけnilになっています。
|
6
6
|
user.update_attributeなどでも試しましたが、同じ結果でした。
|
7
|
+
User.newの時まではuser.emailとしてemailの値を取り出せるのですがuser.saveで保存後にuser.emailとするとnilになります。
|
7
|
-
エラーなども表示されず困っています。考えられる原因などでも良いので
|
8
|
+
エラーなども表示されず困っています。考えられる原因などでも良いのでご教授頂けると幸いです。回答お願い致します。
|
8
9
|
|
9
10
|
**ターミナルで作成**
|
10
11
|

|