質問編集履歴
3
コントローラー、ルーティングの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,6 +32,96 @@
|
|
32
32
|
|
33
33
|
```ここに言語名を入力
|
34
34
|
|
35
|
+
tweets_controllerの開示
|
36
|
+
|
37
|
+
↓
|
38
|
+
|
39
|
+
class TweetsController < ApplicationController
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
before_action :move_to_index, except: :index
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def index
|
48
|
+
|
49
|
+
@tweets = Tweet.order("created_at DESC").page(params[:page]).per(5)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def new
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
def create
|
62
|
+
|
63
|
+
Tweet.create(text:tweet_params[:text], user_id:current_user.id)
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
def destroy
|
70
|
+
|
71
|
+
tweet = Tweet.find(params[:id])
|
72
|
+
|
73
|
+
tweet.destroy if tweet.user_id == current_user.id
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def tweet_params
|
82
|
+
|
83
|
+
params.permit(:text)
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def move_to_index
|
90
|
+
|
91
|
+
redirect_to action: :index unless user_signed_in?
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
config/routes.rbの開示
|
102
|
+
|
103
|
+
↓
|
104
|
+
|
105
|
+
Rails.application.routes.draw do
|
106
|
+
|
107
|
+
devise_for :users
|
108
|
+
|
109
|
+
root 'tweets#index'
|
110
|
+
|
111
|
+
get 'tweets' => 'tweets#index'
|
112
|
+
|
113
|
+
get 'tweets/new' => 'tweets#new'
|
114
|
+
|
115
|
+
post 'tweets' => 'tweets#create'
|
116
|
+
|
117
|
+
delete 'tweets/:id' => 'tweets#destroy'
|
118
|
+
|
119
|
+
get 'users/:id' => 'users#show'
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
35
125
|
rails routesの結果は
|
36
126
|
|
37
127
|
↓
|
2
rails routesの結果を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -31,6 +31,66 @@
|
|
31
31
|
|
32
32
|
|
33
33
|
```ここに言語名を入力
|
34
|
+
|
35
|
+
rails routesの結果は
|
36
|
+
|
37
|
+
↓
|
38
|
+
|
39
|
+
Prefix Verb URI Pattern Controller#Action
|
40
|
+
|
41
|
+
new_user_session GET /users/sign_in(.:format) devise/sessions#new
|
42
|
+
|
43
|
+
user_session POST /users/sign_in(.:format) devise/sessions#create
|
44
|
+
|
45
|
+
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
|
46
|
+
|
47
|
+
new_user_password GET /users/password/new(.:format) devise/passwords#new
|
48
|
+
|
49
|
+
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
|
50
|
+
|
51
|
+
user_password PATCH /users/password(.:format) devise/passwords#update
|
52
|
+
|
53
|
+
PUT /users/password(.:format) devise/passwords#update
|
54
|
+
|
55
|
+
POST /users/password(.:format) devise/passwords#create
|
56
|
+
|
57
|
+
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
|
58
|
+
|
59
|
+
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
|
60
|
+
|
61
|
+
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
|
62
|
+
|
63
|
+
user_registration PATCH /users(.:format) devise/registrations#update
|
64
|
+
|
65
|
+
PUT /users(.:format) devise/registrations#update
|
66
|
+
|
67
|
+
DELETE /users(.:format) devise/registrations#destroy
|
68
|
+
|
69
|
+
POST /users(.:format) devise/registrations#create
|
70
|
+
|
71
|
+
root GET / tweets#index
|
72
|
+
|
73
|
+
tweets GET /tweets(.:format) tweets#index
|
74
|
+
|
75
|
+
tweets_new GET /tweets/new(.:format) tweets#new
|
76
|
+
|
77
|
+
POST /tweets(.:format) tweets#create
|
78
|
+
|
79
|
+
DELETE /tweets/:id(.:format) tweets#destroy
|
80
|
+
|
81
|
+
GET /users/:id(.:format) users#show
|
82
|
+
|
83
|
+
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
|
84
|
+
|
85
|
+
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
|
86
|
+
|
87
|
+
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
|
88
|
+
|
89
|
+
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
|
90
|
+
|
91
|
+
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
|
92
|
+
|
93
|
+
|
34
94
|
|
35
95
|
ルーティングでは delete 'tweets/:id' => 'tweets#destroy' 、
|
36
96
|
|
1
タグを追加した
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|