質問編集履歴
3
profile_controller.rbを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
コード
|
4
|
+
|
1
|
-
### 前提・実現したいこと
|
5
|
+
```### 前提・実現したいこと
|
2
6
|
|
3
7
|
railsでWEBアプリケーションを開発中にエラーが発生してしまった。
|
4
8
|
|
@@ -139,3 +143,43 @@
|
|
139
143
|
end
|
140
144
|
|
141
145
|
```
|
146
|
+
|
147
|
+
profile_controller.rb
|
148
|
+
|
149
|
+
```ここに言語を入力
|
150
|
+
|
151
|
+
def create
|
152
|
+
|
153
|
+
@profile = Profile2.find_by(id: params[:id])
|
154
|
+
|
155
|
+
@profile.name = params[:name],
|
156
|
+
|
157
|
+
@profile.department = params[:department],
|
158
|
+
|
159
|
+
@profile.year = params[:year],
|
160
|
+
|
161
|
+
@profile.comment = params[:comment],
|
162
|
+
|
163
|
+
@profile.contact_info = params[:contact_info],
|
164
|
+
|
165
|
+
@profile.skill = params[:skill]
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
if @profile.save
|
170
|
+
|
171
|
+
session[:user_id] = @profile.id
|
172
|
+
|
173
|
+
flash[:notice] = "プロフィール登録が完了しました"
|
174
|
+
|
175
|
+
redirect_to("/profile2s/#{@profile.id}")
|
176
|
+
|
177
|
+
else
|
178
|
+
|
179
|
+
render("profiles/new")
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
```
|
2
user_controller.rbの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
user_controller.rbを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,3 +65,77 @@
|
|
65
65
|
end
|
66
66
|
|
67
67
|
```
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
user_controller.rb
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
def create
|
76
|
+
|
77
|
+
@user = User.new(
|
78
|
+
|
79
|
+
email: params[:email],
|
80
|
+
|
81
|
+
password: params[:password]
|
82
|
+
|
83
|
+
)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
@profile = Profile2.new(
|
88
|
+
|
89
|
+
id: @user.id
|
90
|
+
|
91
|
+
)
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
if @user.save && @profile.save
|
96
|
+
|
97
|
+
session[:user_id] = @user.id
|
98
|
+
|
99
|
+
flash[:notice] = "ユーザー登録が完了しました"
|
100
|
+
|
101
|
+
redirect_to("/profiles/#{@user.id}")
|
102
|
+
|
103
|
+
else
|
104
|
+
|
105
|
+
render("signup")
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
def login
|
114
|
+
|
115
|
+
@user = User.find_by(email: params[:email])
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
if @user
|
120
|
+
|
121
|
+
session[:user_id] = @user.id
|
122
|
+
|
123
|
+
flash[:notice] = "ログインしました"
|
124
|
+
|
125
|
+
redirect_to("/profiles/#{@user.id}")
|
126
|
+
|
127
|
+
else
|
128
|
+
|
129
|
+
@errors_messages = "メールアドレスまたはパスワードが間違っています"
|
130
|
+
|
131
|
+
@email = params[:email]
|
132
|
+
|
133
|
+
@password = params[:password]
|
134
|
+
|
135
|
+
render("login_form")
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
```
|