質問編集履歴
1
tweetsコントローラーの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -102,4 +102,74 @@
|
|
102
102
|
しかし、変わらずnewではブレビューが表示されるが、editでは表示されなかったです。
|
103
103
|
|
104
104
|
|
105
|
-
以上になります。ご助言いただけると幸いです。
|
105
|
+
以上になります。ご助言いただけると幸いです。
|
106
|
+
|
107
|
+
###追記
|
108
|
+
```controller
|
109
|
+
#tweets
|
110
|
+
|
111
|
+
class TweetsController < ApplicationController
|
112
|
+
before_action :authenticate_user!, only: [:index, :new, :edit]
|
113
|
+
before_action :set_group
|
114
|
+
before_action :set_tweet, only: [:show, :edit, :update, :destroy]
|
115
|
+
|
116
|
+
def index
|
117
|
+
@tweets = @group.tweets.includes(:user).order("created_at DESC")
|
118
|
+
end
|
119
|
+
|
120
|
+
def new
|
121
|
+
@tweet = Tweet.new
|
122
|
+
end
|
123
|
+
|
124
|
+
def create
|
125
|
+
@tweet = @group.tweets.new(tweet_params)
|
126
|
+
if @tweet.save
|
127
|
+
redirect_to group_tweets_path(@group)
|
128
|
+
else
|
129
|
+
@tweets = @group.tweets.includes(:user)
|
130
|
+
render :new
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def show
|
135
|
+
end
|
136
|
+
|
137
|
+
def edit
|
138
|
+
unless user_signed_in? && current_user.id == @tweet.user_id
|
139
|
+
redirect_to root_path
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def update
|
144
|
+
if @tweet.update(tweet_params)
|
145
|
+
redirect_to group_tweets_path(@group)
|
146
|
+
else
|
147
|
+
render :edit
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def destroy
|
152
|
+
if current_user.id == @tweet.user_id
|
153
|
+
@tweet.destroy
|
154
|
+
redirect_to group_tweets_path(@group)
|
155
|
+
else
|
156
|
+
render :index
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def tweet_params
|
163
|
+
params.require(:tweet).permit(:content, :image).merge(user_id: current_user.id)
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_group
|
167
|
+
@group = Group.find(params[:group_id])
|
168
|
+
end
|
169
|
+
|
170
|
+
def set_tweet
|
171
|
+
@tweet = @group.tweets.find(params[:id])
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
```
|