質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,7 +72,7 @@
|
|
72
72
|
|
73
73
|
<%= c.content %>
|
74
74
|
|
75
|
-
<% if c.user %>
|
75
|
+
<% if c.user_id == current_user.id %>
|
76
76
|
|
77
77
|
<%= link_to "削除", comment_path(c), method: :delete, class: "comment-menus" %>
|
78
78
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -106,126 +106,128 @@
|
|
106
106
|
|
107
107
|
def show
|
108
108
|
|
109
|
+
|
110
|
+
|
111
|
+
@post = Post.find_by(id: params[:id])
|
112
|
+
|
113
|
+
@user = @post.user
|
114
|
+
|
115
|
+
@post = Post.find(params[:id])
|
116
|
+
|
117
|
+
@comments = @post.comments
|
118
|
+
|
119
|
+
@comment = Comment.new
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def new
|
126
|
+
|
127
|
+
@post = Post.new
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
def create
|
134
|
+
|
135
|
+
@post = Post.new(
|
136
|
+
|
137
|
+
content: params[:content],
|
138
|
+
|
139
|
+
user_id: @current_user.id,
|
140
|
+
|
141
|
+
)
|
142
|
+
|
143
|
+
if params[:post].present?
|
144
|
+
|
145
|
+
@post.video = params[:post][:video]
|
146
|
+
|
147
|
+
print params
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
if @post.save
|
152
|
+
|
153
|
+
flash[:notice] = "投稿を作成しました"
|
154
|
+
|
155
|
+
redirect_to("/posts/index")
|
156
|
+
|
157
|
+
else
|
158
|
+
|
159
|
+
render("posts/new")
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
def edit
|
168
|
+
|
169
|
+
@post = Post.find_by(id: params[:id])
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
def update
|
176
|
+
|
177
|
+
@post = Post.find_by(id: params[:id])
|
178
|
+
|
179
|
+
@post.content = params[:content]
|
180
|
+
|
181
|
+
if @post.save
|
182
|
+
|
183
|
+
flash[:notice] = "投稿を編集しました"
|
184
|
+
|
185
|
+
redirect_to("/posts/index")
|
186
|
+
|
187
|
+
else
|
188
|
+
|
189
|
+
render("posts/edit")
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
def destroy
|
198
|
+
|
109
199
|
unless c.user_id == cuirrent_user.id
|
110
200
|
|
111
201
|
flash[:notice] = "コメントを削除しました"
|
112
202
|
|
113
203
|
end
|
114
204
|
|
115
|
-
|
205
|
+
@post = Post.find_by(id: params[:id])
|
116
|
-
|
206
|
+
|
117
|
-
|
207
|
+
@post.destroy
|
118
|
-
|
119
|
-
|
208
|
+
|
120
|
-
|
121
|
-
|
209
|
+
flash[:notice] = "投稿を削除しました"
|
122
|
-
|
210
|
+
|
123
|
-
|
211
|
+
redirect_to("/posts/index")
|
124
|
-
|
212
|
+
|
125
|
-
|
213
|
+
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
214
|
+
|
130
|
-
|
131
|
-
|
215
|
+
|
132
|
-
|
133
|
-
|
216
|
+
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
217
|
+
def ensure_correct_user
|
138
|
-
|
218
|
+
|
139
|
-
@post = Post.n
|
219
|
+
@post = Post.find_by(id: params[:id])
|
140
|
-
|
141
|
-
|
220
|
+
|
142
|
-
|
143
|
-
user_id
|
221
|
+
if @post.user_id != @current_user.id
|
144
|
-
|
145
|
-
|
222
|
+
|
146
|
-
|
147
|
-
if params[:post].present?
|
148
|
-
|
149
|
-
|
223
|
+
flash[:notice] = "権限がありません"
|
150
|
-
|
224
|
+
|
151
|
-
|
225
|
+
redirect_to("/posts/index")
|
152
226
|
|
153
227
|
end
|
154
228
|
|
155
|
-
if @post.save
|
156
|
-
|
157
|
-
flash[:notice] = "投稿を作成しました"
|
158
|
-
|
159
|
-
redirect_to("/posts/index")
|
160
|
-
|
161
|
-
else
|
162
|
-
|
163
|
-
render("posts/new")
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
def edit
|
172
|
-
|
173
|
-
@post = Post.find_by(id: params[:id])
|
174
|
-
|
175
229
|
end
|
176
230
|
|
177
|
-
|
178
|
-
|
179
|
-
def update
|
180
|
-
|
181
|
-
@post = Post.find_by(id: params[:id])
|
182
|
-
|
183
|
-
@post.content = params[:content]
|
184
|
-
|
185
|
-
if @post.save
|
186
|
-
|
187
|
-
flash[:notice] = "投稿を編集しました"
|
188
|
-
|
189
|
-
redirect_to("/posts/index")
|
190
|
-
|
191
|
-
else
|
192
|
-
|
193
|
-
render("posts/edit")
|
194
|
-
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
def destroy
|
202
|
-
|
203
|
-
@post = Post.find_by(id: params[:id])
|
204
|
-
|
205
|
-
@post.destroy
|
206
|
-
|
207
|
-
flash[:notice] = "投稿を削除しました"
|
208
|
-
|
209
|
-
redirect_to("/posts/index")
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
def ensure_correct_user
|
216
|
-
|
217
|
-
@post = Post.find_by(id: params[:id])
|
218
|
-
|
219
|
-
if @post.user_id != @current_user.id
|
220
|
-
|
221
|
-
flash[:notice] = "権限がありません"
|
222
|
-
|
223
|
-
redirect_to("/posts/index")
|
224
|
-
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
231
|
end
|
230
232
|
|
231
233
|
```
|