質問編集履歴
3
modelコード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -180,8 +180,6 @@
|
|
180
180
|
|
181
181
|
```
|
182
182
|
|
183
|
-
|
184
|
-
|
185
183
|
### 試したこと
|
186
184
|
|
187
185
|
|
@@ -189,3 +187,113 @@
|
|
189
187
|
- 部分テンプレートをViewに差し込みましたが、同様のエラーとなり動作しませんでした
|
190
188
|
|
191
189
|
- @itemが正常に渡せていないと思い、@userやcurrent_userに修正しても動作しませんでした
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
◆追記
|
196
|
+
|
197
|
+
modelのコードです
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
```item
|
202
|
+
|
203
|
+
class Item < ApplicationRecord
|
204
|
+
|
205
|
+
belongs_to :user, optional: true
|
206
|
+
|
207
|
+
has_many :favorites, dependent: :destroy
|
208
|
+
|
209
|
+
has_many :item_comments, dependent: :destroy
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
attachment :item_image
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
def favorited_by?(user)
|
218
|
+
|
219
|
+
favorites.where(user_id: user.id).exsits?
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
validates :name, presence: true
|
226
|
+
|
227
|
+
validates :body, presence: true, length:{maximum: 200}
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
```user
|
234
|
+
|
235
|
+
class User < ApplicationRecord
|
236
|
+
|
237
|
+
# Include default devise modules. Others available are:
|
238
|
+
|
239
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
240
|
+
|
241
|
+
devise :database_authenticatable, :registerable,
|
242
|
+
|
243
|
+
:recoverable, :rememberable, :validatable
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
has_many :items, dependent: :destroy
|
248
|
+
|
249
|
+
has_many :favorites, dependent: :destroy
|
250
|
+
|
251
|
+
has_many :item_comments, dependent: :destroy
|
252
|
+
|
253
|
+
attachment :profile_image, destroy: false
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
has_many :reverse_of_relationships, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy
|
258
|
+
|
259
|
+
has_many :followers, through: :reverse_of_relationships, source: :follower
|
260
|
+
|
261
|
+
has_many :relationships, class_name: "Relationship", foreign_key: "follower_id", dependent: :destroy
|
262
|
+
|
263
|
+
has_many :followings, through: :relationships, source: :followed
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
def follow(user_id)
|
268
|
+
|
269
|
+
relationships.create(followed_id: user_id)
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
def unfollow(user_id)
|
276
|
+
|
277
|
+
relationships.find_by(followed_id: user_id).destroy
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
def following?(user)
|
284
|
+
|
285
|
+
followings.include?(user)
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
validates :name, presence: true, length:{minimum: 2}, uniqueness: true
|
292
|
+
|
293
|
+
validates :introduction, length:{maximum: 200}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
```
|
2
初心者アイコンを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
### 前提・実現したいこと
|
1
|
+
### 前提・実現したいこと
|
2
2
|
|
3
3
|
|
4
4
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
NoMethodError in Items#show
|
24
24
|
|
25
|
-
Showing /
|
25
|
+
Showing .../app/views/users/_info.html.erb where line #5 raised:
|
26
26
|
|
27
27
|
|
28
28
|
|