質問編集履歴
1
コントローラー部分のコードをを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,6 +110,156 @@
|
|
110
110
|
|
111
111
|
|
112
112
|
|
113
|
+
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
**users_controller.rb**
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
class UsersController < ApplicationController
|
126
|
+
|
127
|
+
before_action :logged_in_user, only: [:index, :edit, :update]
|
128
|
+
|
129
|
+
before_action :correct_user, only: [:edit, :update]
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
def index
|
134
|
+
|
135
|
+
@users = User.paginate(page: params[:page])
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def show
|
142
|
+
|
143
|
+
@user = User.find(params[:id])
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
def new
|
150
|
+
|
151
|
+
@user = User.new
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
def create
|
158
|
+
|
159
|
+
@user = User.new(user_params)
|
160
|
+
|
161
|
+
if @user.save
|
162
|
+
|
163
|
+
log_in @user
|
164
|
+
|
165
|
+
flash[:success] = "Welcome to the Sample App!"
|
166
|
+
|
167
|
+
redirect_to @user
|
168
|
+
|
169
|
+
else
|
170
|
+
|
171
|
+
render 'new'
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
def edit
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
def update
|
188
|
+
|
189
|
+
if @user.update_attributes(user_params)
|
190
|
+
|
191
|
+
flash[:success] = "Profile updated"
|
192
|
+
|
193
|
+
redirect_to @user
|
194
|
+
|
195
|
+
else
|
196
|
+
|
197
|
+
render 'edit'
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
def user_params
|
210
|
+
|
211
|
+
params.require(:user).permit(:name, :email, :password,
|
212
|
+
|
213
|
+
:password_confirmation)
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
# ログイン済みユーザーかどうか確認
|
224
|
+
|
225
|
+
def logged_in_user
|
226
|
+
|
227
|
+
unless logged_in?
|
228
|
+
|
229
|
+
flash[:danger] = "Please log in."
|
230
|
+
|
231
|
+
redirect_to login_url
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
# 正しいユーザーかどうか確認
|
242
|
+
|
243
|
+
def correct_user
|
244
|
+
|
245
|
+
@user = User.find(params[:id])
|
246
|
+
|
247
|
+
redirect_to(root_url) unless current_user?(@user)
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
113
263
|
エラ〜メッセージを元に調べてみたのですが、引数の数が間違っている?(そもそもエラーメッセージの解釈が間違っていたらすいません)ようなのですが具体的に何をすればいいのかわかりません
|
114
264
|
|
115
265
|
|