質問編集履歴
6
みやすくするため
test
CHANGED
File without changes
|
test
CHANGED
@@ -391,117 +391,3 @@
|
|
391
391
|
end
|
392
392
|
|
393
393
|
end
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
解決方法
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
class PostsController < ApplicationController
|
420
|
-
|
421
|
-
def index
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
@posts = Post.all
|
426
|
-
|
427
|
-
end
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
def new
|
432
|
-
|
433
|
-
@post = Post.new
|
434
|
-
|
435
|
-
end
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
def create
|
440
|
-
|
441
|
-
Post.create(post_params)
|
442
|
-
|
443
|
-
end
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
def edit
|
450
|
-
|
451
|
-
@post = Post.find(params[:id])
|
452
|
-
|
453
|
-
end
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
def show
|
462
|
-
|
463
|
-
end
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
def update
|
468
|
-
|
469
|
-
@post = Post.find(params[:id])
|
470
|
-
|
471
|
-
if post.user_id == current_user.id
|
472
|
-
|
473
|
-
post.update(post_params)
|
474
|
-
|
475
|
-
end
|
476
|
-
|
477
|
-
end
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
def destroy
|
484
|
-
|
485
|
-
post = Post.find(params[:id])
|
486
|
-
|
487
|
-
if post.user_id == current_user.id
|
488
|
-
|
489
|
-
post.destroy
|
490
|
-
|
491
|
-
end
|
492
|
-
|
493
|
-
end
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
private
|
500
|
-
|
501
|
-
def post_params
|
502
|
-
|
503
|
-
params.require(:post).permit(:text).merge(user_id: current_user.id)
|
504
|
-
|
505
|
-
end
|
506
|
-
|
507
|
-
end
|
5
みやすくするため
test
CHANGED
File without changes
|
test
CHANGED
@@ -396,4 +396,112 @@
|
|
396
396
|
|
397
397
|
|
398
398
|
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
解決方法
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
class PostsController < ApplicationController
|
420
|
+
|
421
|
+
def index
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
@posts = Post.all
|
426
|
+
|
427
|
+
end
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
def new
|
432
|
+
|
433
|
+
@post = Post.new
|
434
|
+
|
435
|
+
end
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
def create
|
440
|
+
|
441
|
+
Post.create(post_params)
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
def edit
|
450
|
+
|
451
|
+
@post = Post.find(params[:id])
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
def show
|
462
|
+
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
def update
|
468
|
+
|
469
|
+
@post = Post.find(params[:id])
|
470
|
+
|
471
|
+
if post.user_id == current_user.id
|
472
|
+
|
473
|
+
post.update(post_params)
|
474
|
+
|
475
|
+
end
|
476
|
+
|
477
|
+
end
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
def destroy
|
484
|
+
|
485
|
+
post = Post.find(params[:id])
|
486
|
+
|
487
|
+
if post.user_id == current_user.id
|
488
|
+
|
489
|
+
post.destroy
|
490
|
+
|
491
|
+
end
|
492
|
+
|
493
|
+
end
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
private
|
500
|
+
|
501
|
+
def post_params
|
502
|
+
|
399
|
-
|
503
|
+
params.require(:post).permit(:text).merge(user_id: current_user.id)
|
504
|
+
|
505
|
+
end
|
506
|
+
|
507
|
+
end
|
4
みやすくするため
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
railsにおいて編集が反映されない件について
|
1
|
+
srailsにおいて編集が反映されない件について
|
test
CHANGED
@@ -210,19 +210,151 @@
|
|
210
210
|
|
211
211
|
|
212
212
|
|
213
|
+
def destroy
|
214
|
+
|
215
|
+
post = Post.find(params[:id])
|
216
|
+
|
217
|
+
if post.user_id == current_user.id
|
218
|
+
|
219
|
+
post.destroy
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
private
|
230
|
+
|
231
|
+
def post_params
|
232
|
+
|
233
|
+
params.require(:post).permit(:text).merge(user_id: current_user.id)
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
```
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
```index
|
246
|
+
|
247
|
+
<div class="posts">
|
248
|
+
|
249
|
+
<% @posts.each do |post| %>
|
250
|
+
|
251
|
+
<li>
|
252
|
+
|
253
|
+
<%= link_to '削除', "/posts/#{post.id}", method: :delete %>
|
254
|
+
|
255
|
+
</li>
|
256
|
+
|
257
|
+
<li>
|
258
|
+
|
259
|
+
<%= link_to '編集', "/posts/#{post.id}/edit", method: :get %>
|
260
|
+
|
261
|
+
</li>
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
<%= simple_format(post.text) %>
|
266
|
+
|
267
|
+
<% end %>
|
268
|
+
|
269
|
+
</div>
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
```
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
```new
|
278
|
+
|
279
|
+
<div class = "posts">
|
280
|
+
|
281
|
+
<%= form_for(@post) do |f| %>
|
282
|
+
|
283
|
+
<%= f.text_field :text %>
|
284
|
+
|
285
|
+
<%= f.submit '投稿' %>
|
286
|
+
|
287
|
+
<% end %>
|
288
|
+
|
289
|
+
</div>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
```
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
```edit
|
298
|
+
|
299
|
+
<div class = "posts">
|
300
|
+
|
301
|
+
<%= form_for(@post) do |f| %>
|
302
|
+
|
303
|
+
<%= f.text_field :text %>
|
304
|
+
|
305
|
+
<%= f.submit '投稿' %>
|
306
|
+
|
307
|
+
<% end %>
|
308
|
+
|
309
|
+
</div>
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
```
|
314
|
+
|
315
|
+
```update
|
316
|
+
|
317
|
+
<div class = "posts">
|
318
|
+
|
319
|
+
<h3> you posted </h3>
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
<a class = " btn " href= "/posts"> go to home </a>
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
</div>
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
```
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
どうかお力を貸していただけると助かります。よろしくお願いします。
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
postcontroller
|
348
|
+
|
349
|
+
|
350
|
+
|
213
351
|
def update
|
214
352
|
|
215
|
-
end
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
def destroy
|
220
|
-
|
221
|
-
post = Post.find(params[:id])
|
353
|
+
@post = Post.find(params[:id])
|
222
|
-
|
354
|
+
|
223
|
-
if post.user_id == current_user.id
|
355
|
+
if @post.user_id == current_user.id
|
224
|
-
|
356
|
+
|
225
|
-
post.destr
|
357
|
+
post.update(post_params)
|
226
358
|
|
227
359
|
end
|
228
360
|
|
@@ -232,118 +364,36 @@
|
|
232
364
|
|
233
365
|
|
234
366
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
<%= simple_format(post.text) %>
|
272
|
-
|
273
|
-
<% end %>
|
274
|
-
|
275
|
-
</div>
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
```
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
```new
|
284
|
-
|
285
|
-
<div class = "posts">
|
286
|
-
|
287
|
-
<%= form_for(@post) do |f| %>
|
288
|
-
|
289
|
-
<%= f.text_field :text %>
|
290
|
-
|
291
|
-
<%= f.submit '投稿' %>
|
292
|
-
|
293
|
-
<% end %>
|
294
|
-
|
295
|
-
</div>
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
```
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
```edit
|
304
|
-
|
305
|
-
<div class = "posts">
|
306
|
-
|
307
|
-
<%= form_for(@post) do |f| %>
|
308
|
-
|
309
|
-
<%= f.text_field :text %>
|
310
|
-
|
311
|
-
<%= f.submit '投稿' %>
|
312
|
-
|
313
|
-
<% end %>
|
314
|
-
|
315
|
-
</div>
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
```
|
320
|
-
|
321
|
-
```update
|
322
|
-
|
323
|
-
<div class = "posts">
|
324
|
-
|
325
|
-
<h3> you posted </h3>
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
<a class = " btn " href= "/posts"> go to home </a>
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
</div>
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
```
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
どうかお力を貸していただけると助かります。よろしくお願いします。
|
367
|
+
postから@postに変更させていただきました。
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
結果このようにエラーが出ました。
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
NameError in PostsController#update
|
380
|
+
|
381
|
+
undefined local variable or method `post' for #<> Did you mean? @post
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
@post = Post.find(params[:id])
|
386
|
+
|
387
|
+
if @post.user_id == current_user.id
|
388
|
+
|
389
|
+
post.update(post_params) 赤のライン
|
390
|
+
|
391
|
+
end
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
Parameters: {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"", "post"=>{"text"=>"s"}, "commit"=>"投稿", "id"=>"5"}
|
3
みやすくするため
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,7 +52,7 @@
|
|
52
52
|
|
53
53
|
---
|
54
54
|
|
55
|
-
このようになるのでddddddの部分をupdatedに変えて
|
55
|
+
このようになるのでddddddの部分をupdatedに変えて
|
56
56
|
|
57
57
|
|
58
58
|
|
@@ -72,7 +72,27 @@
|
|
72
72
|
|
73
73
|
---
|
74
74
|
|
75
|
+
投稿ボタンを押して
|
76
|
+
|
77
|
+
http://localhost:3000/posts/5
|
78
|
+
|
79
|
+
---
|
80
|
+
|
81
|
+
ログインアプリ
|
82
|
+
|
83
|
+
ログアウト
|
84
|
+
|
85
|
+
マイページ
|
86
|
+
|
87
|
+
投稿する
|
88
|
+
|
89
|
+
you posted
|
90
|
+
|
91
|
+
go to home
|
92
|
+
|
93
|
+
---
|
94
|
+
|
75
|
-
|
95
|
+
go to homeを押してホームに戻っても
|
76
96
|
|
77
97
|
|
78
98
|
|
2
みやすくするため
test
CHANGED
File without changes
|
test
CHANGED
@@ -114,7 +114,7 @@
|
|
114
114
|
|
115
115
|
devise_for :users
|
116
116
|
|
117
|
-
|
117
|
+
|
118
118
|
|
119
119
|
root to: 'posts#index'
|
120
120
|
|
1
みやすくするため
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,8 +60,6 @@
|
|
60
60
|
|
61
61
|
ログインアプリ
|
62
62
|
|
63
|
-
メールアドレス: 1@1
|
64
|
-
|
65
63
|
ログアウト
|
66
64
|
|
67
65
|
マイページ
|