質問編集履歴
1
ファイルを全て記入しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Micropost
|
1
|
+
Micropostにお気に入り機能を追加したいです。
|
test
CHANGED
@@ -78,17 +78,123 @@
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
81
87
|
②user_contoroller.rb
|
82
88
|
|
83
89
|
|
84
90
|
|
91
|
+
class UsersController < ApplicationController
|
92
|
+
|
93
|
+
before_action :require_user_logged_in, only: [:index, :show, :followings, :followers, :likes]
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
def index
|
98
|
+
|
99
|
+
@users = User.order(id: :desc).page(params[:page]).per(25)
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
def show
|
106
|
+
|
107
|
+
@user = User.find(params[:id])
|
108
|
+
|
109
|
+
@microposts = @user.microposts.order(id: :desc).page(params[:page])
|
110
|
+
|
111
|
+
counts(@user)
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
def new
|
118
|
+
|
119
|
+
@user = User.new
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def create
|
126
|
+
|
127
|
+
@user = User.new(user_params)
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
if @user.save
|
132
|
+
|
133
|
+
flash[:success] = 'ユーザを登録しました。'
|
134
|
+
|
135
|
+
redirect_to @user
|
136
|
+
|
137
|
+
else
|
138
|
+
|
139
|
+
flash.now[:danger] = 'ユーザの登録に失敗しました。'
|
140
|
+
|
141
|
+
render :new
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
def followings
|
150
|
+
|
151
|
+
@user = User.find(params[:id])
|
152
|
+
|
153
|
+
@followings = @user.followings.page(params[:page])
|
154
|
+
|
155
|
+
counts(@user)
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
def followers
|
162
|
+
|
163
|
+
@user = User.find(params[:id])
|
164
|
+
|
165
|
+
@followers = @user.followers.page(params[:page])
|
166
|
+
|
167
|
+
counts(@user)
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
|
85
|
-
def likes
|
173
|
+
def likes
|
86
|
-
|
174
|
+
|
87
|
-
@micropost = Microposts.find(params[:id])
|
175
|
+
@micropost = Microposts.find(params[:id])
|
88
|
-
|
176
|
+
|
89
|
-
counts(microposts)
|
177
|
+
counts(microposts)
|
90
|
-
|
178
|
+
|
91
|
-
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
private
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
def user_params
|
188
|
+
|
189
|
+
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
|
92
198
|
|
93
199
|
|
94
200
|
|