質問編集履歴
1
controllerのファイルを載せました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,6 +62,110 @@
|
|
62
62
|
|
63
63
|
```
|
64
64
|
|
65
|
+
追加のファイル
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
**users_controller.rb**
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
```class UsersController < ApplicationController
|
74
|
+
|
75
|
+
before_action :require_user_logged_in, only: [:index, :show, :followings, :followers]
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
def index
|
80
|
+
|
81
|
+
@users = User.all.page(params[:page])
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def show
|
88
|
+
|
89
|
+
@user = User.find(params[:id])
|
90
|
+
|
91
|
+
@microposts = @user.microposts.order('created_at DESC').page(params[:page])
|
92
|
+
|
93
|
+
counts(@user)
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def new
|
100
|
+
|
101
|
+
@user = User.new
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
def create
|
108
|
+
|
109
|
+
@user = User.new(user_params)
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
if @user.save
|
114
|
+
|
115
|
+
flash[:success] = 'ユーザーを登録しました。'
|
116
|
+
|
117
|
+
redirect_to @user
|
118
|
+
|
119
|
+
else
|
120
|
+
|
121
|
+
flash.now[:danger] = 'ユーザの登録に失敗しました。'
|
122
|
+
|
123
|
+
render :new
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def followings
|
130
|
+
|
131
|
+
@user = User.find(params[:id])
|
132
|
+
|
133
|
+
@followings = @user.followings.page(parmas[:page])
|
134
|
+
|
135
|
+
counts(@user)
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def followers
|
142
|
+
|
143
|
+
@user = User.find(params[:id])
|
144
|
+
|
145
|
+
@followers = @user.followers.page(params[:page])
|
146
|
+
|
147
|
+
counts(@user)
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
def user_params
|
158
|
+
|
159
|
+
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
```
|
168
|
+
|
65
169
|
|
66
170
|
|
67
171
|
|