質問編集履歴
4
タイトルの編集
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<rails>
|
1
|
+
<rails-tutorial> Cloud9上のブラウザ表示がおかしい
|
test
CHANGED
File without changes
|
3
controller記述の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -362,6 +362,162 @@
|
|
362
362
|
|
363
363
|
|
364
364
|
|
365
|
+
#追記 microposts controller
|
366
|
+
|
367
|
+
```rails
|
368
|
+
|
369
|
+
class MicropostsController < ApplicationController
|
370
|
+
|
371
|
+
before_action :set_micropost, only: [:show, :edit, :update, :destroy]
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
# GET /microposts
|
376
|
+
|
377
|
+
# GET /microposts.json
|
378
|
+
|
379
|
+
def index
|
380
|
+
|
381
|
+
@microposts = Micropost.all
|
382
|
+
|
383
|
+
end
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
# GET /microposts/1
|
388
|
+
|
389
|
+
# GET /microposts/1.json
|
390
|
+
|
391
|
+
def show
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
# GET /microposts/new
|
398
|
+
|
399
|
+
def new
|
400
|
+
|
401
|
+
@micropost = Micropost.new
|
402
|
+
|
403
|
+
end
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
# GET /microposts/1/edit
|
408
|
+
|
409
|
+
def edit
|
410
|
+
|
411
|
+
end
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
# POST /microposts
|
416
|
+
|
417
|
+
# POST /microposts.json
|
418
|
+
|
419
|
+
def create
|
420
|
+
|
421
|
+
@micropost = Micropost.new(micropost_params)
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
respond_to do |format|
|
426
|
+
|
427
|
+
if @micropost.save
|
428
|
+
|
429
|
+
format.html { redirect_to @micropost, notice: 'Micropost was successfully created.' }
|
430
|
+
|
431
|
+
format.json { render :show, status: :created, location: @micropost }
|
432
|
+
|
433
|
+
else
|
434
|
+
|
435
|
+
format.html { render :new }
|
436
|
+
|
437
|
+
format.json { render json: @micropost.errors, status: :unprocessable_entity }
|
438
|
+
|
439
|
+
end
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
# PATCH/PUT /microposts/1
|
448
|
+
|
449
|
+
# PATCH/PUT /microposts/1.json
|
450
|
+
|
451
|
+
def update
|
452
|
+
|
453
|
+
respond_to do |format|
|
454
|
+
|
455
|
+
if @micropost.update(micropost_params)
|
456
|
+
|
457
|
+
format.html { redirect_to @micropost, notice: 'Micropost was successfully updated.' }
|
458
|
+
|
459
|
+
format.json { render :show, status: :ok, location: @micropost }
|
460
|
+
|
461
|
+
else
|
462
|
+
|
463
|
+
format.html { render :edit }
|
464
|
+
|
465
|
+
format.json { render json: @micropost.errors, status: :unprocessable_entity }
|
466
|
+
|
467
|
+
end
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
end
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
# DELETE /microposts/1
|
476
|
+
|
477
|
+
# DELETE /microposts/1.json
|
478
|
+
|
479
|
+
def destroy
|
480
|
+
|
481
|
+
@micropost.destroy
|
482
|
+
|
483
|
+
respond_to do |format|
|
484
|
+
|
485
|
+
format.html { redirect_to microposts_url, notice: 'Micropost was successfully destroyed.' }
|
486
|
+
|
487
|
+
format.json { head :no_content }
|
488
|
+
|
489
|
+
end
|
490
|
+
|
491
|
+
end
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
private
|
496
|
+
|
497
|
+
# Use callbacks to share common setup or constraints between actions.
|
498
|
+
|
499
|
+
def set_micropost
|
500
|
+
|
501
|
+
@micropost = Micropost.find(params[:id])
|
502
|
+
|
503
|
+
end
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
508
|
+
|
509
|
+
def micropost_params
|
510
|
+
|
511
|
+
params.require(:micropost).permit(:content, :user_id)
|
512
|
+
|
513
|
+
end
|
514
|
+
|
515
|
+
end
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
```
|
520
|
+
|
365
521
|
|
366
522
|
|
367
523
|
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -306,9 +306,11 @@
|
|
306
306
|
|
307
307
|
|
308
308
|
|
309
|
-
|
310
|
-
|
311
|
-
|
309
|
+
#ブラウザの表示
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
```
|
312
314
|
|
313
315
|
[
|
314
316
|
|
@@ -328,7 +330,11 @@
|
|
328
330
|
|
329
331
|
|
330
332
|
|
331
|
-
|
333
|
+
#routesの追記
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
```rails
|
332
338
|
|
333
339
|
Rails.application.routes.draw do
|
334
340
|
|
1
routesの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -328,6 +328,26 @@
|
|
328
328
|
|
329
329
|
|
330
330
|
|
331
|
+
```rails(routesの追記)
|
332
|
+
|
333
|
+
Rails.application.routes.draw do
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
resources :microposts
|
338
|
+
|
339
|
+
resources :users
|
340
|
+
|
341
|
+
root 'users#index'
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
```
|
348
|
+
|
349
|
+
|
350
|
+
|
331
351
|
#エラー後の対処
|
332
352
|
|
333
353
|
再度Bitbucket,herokuにプッシュし直すなどしてみましたが
|