質問編集履歴
1
コントローラーの中身の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -123,3 +123,167 @@
|
|
123
123
|
</table>
|
124
124
|
|
125
125
|
```
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```ここに言語を入力
|
130
|
+
|
131
|
+
def new
|
132
|
+
|
133
|
+
@teacher = Teacher.new
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
def show
|
140
|
+
|
141
|
+
@teacher = Teacher.find_by(id: params[:id])
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
def create
|
148
|
+
|
149
|
+
@teacher = Teacher.new(teacher_params)
|
150
|
+
|
151
|
+
if @teacher.save
|
152
|
+
|
153
|
+
flash[:notice] = "家庭教師登録が完了しました"
|
154
|
+
|
155
|
+
redirect_to("/teachers/#{@teacher.id}")
|
156
|
+
|
157
|
+
else
|
158
|
+
|
159
|
+
render("teachers/new")
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
def edit
|
168
|
+
|
169
|
+
@teacher = Teacher.find_by(id: params[:id])
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
# updateアクションを作成してください
|
176
|
+
|
177
|
+
def update
|
178
|
+
|
179
|
+
@teacher = Teacher.find_by(id: params[:id])
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
if params[:image]
|
184
|
+
|
185
|
+
@teacher.img = "#{@teacher.id}.jpg"
|
186
|
+
|
187
|
+
image = params[:image]
|
188
|
+
|
189
|
+
File.binwrite("public/teacher_images/#{@teacher.img}", image.read)
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
if @teacher.update(teacher_params)
|
196
|
+
|
197
|
+
flash[:notice] = "ユーザー情報を編集しました"
|
198
|
+
|
199
|
+
redirect_to("/teachers/#{@teacher.id}")
|
200
|
+
|
201
|
+
else
|
202
|
+
|
203
|
+
flash[:notice] = "編集できませんでした"
|
204
|
+
|
205
|
+
render("teachers/edit")
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
def login_form
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
def login
|
220
|
+
|
221
|
+
@teacher = Teacher.find_by(email: params[:email])
|
222
|
+
|
223
|
+
if @teacher && @teacher.authenticate(params[:password])
|
224
|
+
|
225
|
+
session[:teacher_id] = @teacher.id
|
226
|
+
|
227
|
+
flash[:notice] = "ログインしました"
|
228
|
+
|
229
|
+
redirect_to("/")
|
230
|
+
|
231
|
+
else
|
232
|
+
|
233
|
+
@error_message = "メールアドレスまたはパスワードが間違っています"
|
234
|
+
|
235
|
+
@email = params[:email]
|
236
|
+
|
237
|
+
@password = params[:password]
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
render("teachers/login_form")
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
def logout
|
250
|
+
|
251
|
+
session[:teacher_id] = nil
|
252
|
+
|
253
|
+
flash[:notice] = "ログアウトしました"
|
254
|
+
|
255
|
+
redirect_to("/login")
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
# ensure_correct_userを定義してください
|
262
|
+
|
263
|
+
def ensure_correct_teacher
|
264
|
+
|
265
|
+
if @current_teacher.id != params[:id].to_i
|
266
|
+
|
267
|
+
flash[:notice] = "権限がありません"
|
268
|
+
|
269
|
+
redirect_to("/")
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
private
|
278
|
+
|
279
|
+
def teacher_params
|
280
|
+
|
281
|
+
params.permit(:name, :email, :password, :nickname, :gender, :university, :wage, :trafficwage, :time, :prefecture, :region, :profile, :message)
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
```
|