質問編集履歴
1
エラー画面、並びにコントローラーの内容を正しいものに修正しました。何卒よろしくお願いいたします。
test
CHANGED
File without changes
|
test
CHANGED
@@ -152,7 +152,7 @@
|
|
152
152
|
|
153
153
|
【コントローラー】
|
154
154
|
|
155
|
-
```app>controllers>articles_controller.rb
|
155
|
+
```ruby:app>controllers>articles_controller.rb
|
156
156
|
|
157
157
|
class ArticlesController < ApplicationController
|
158
158
|
|
@@ -162,11 +162,27 @@
|
|
162
162
|
|
163
163
|
|
164
164
|
|
165
|
+
before_action :move_to_index, except: [:index, :show]
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
def index
|
170
|
+
|
171
|
+
@articles = Article.includes(:user).order("created_at DESC")
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
def new
|
178
|
+
|
179
|
+
end
|
180
|
+
|
165
181
|
|
166
182
|
|
167
183
|
def create
|
168
184
|
|
169
|
-
url = article_params[:url]
|
185
|
+
url = article_params[:url] #scraping対象URL
|
170
186
|
|
171
187
|
charset = nil
|
172
188
|
|
@@ -180,8 +196,6 @@
|
|
180
196
|
|
181
197
|
image_url = doc.css('img').attribute('src').value
|
182
198
|
|
183
|
-
|
184
|
-
|
185
199
|
scrape = insert_scrape(url, title, image_url)
|
186
200
|
|
187
201
|
article = scrape.articles.build(article_params)
|
@@ -190,6 +204,46 @@
|
|
190
204
|
|
191
205
|
|
192
206
|
|
207
|
+
def show
|
208
|
+
|
209
|
+
@article = Article.find(params[:id])
|
210
|
+
|
211
|
+
@comments = @article.comments.includes(:user)
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
def destroy
|
218
|
+
|
219
|
+
article = Article.find(params[:id])
|
220
|
+
|
221
|
+
article.destroy if article.user_id == current_user.id
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
def edit
|
228
|
+
|
229
|
+
@article = Article.find(params[:id])
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
def update
|
236
|
+
|
237
|
+
article = Article.find(params[:id])
|
238
|
+
|
239
|
+
if article.user_id == current_user.id
|
240
|
+
|
241
|
+
article.update(article_params)
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
193
247
|
|
194
248
|
|
195
249
|
private
|
@@ -204,6 +258,12 @@
|
|
204
258
|
|
205
259
|
|
206
260
|
|
261
|
+
def move_to_index
|
262
|
+
|
263
|
+
redirect_to action: :index unless user_signed_in?
|
264
|
+
|
265
|
+
end
|
266
|
+
|
207
267
|
|
208
268
|
|
209
269
|
def insert_scrape(url, title, image_url)
|
@@ -240,6 +300,8 @@
|
|
240
300
|
|
241
301
|
article.save!
|
242
302
|
|
303
|
+
|
304
|
+
|
243
305
|
end
|
244
306
|
|
245
307
|
|
@@ -256,10 +318,6 @@
|
|
256
318
|
|
257
319
|
end
|
258
320
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
321
|
end
|
264
322
|
|
265
323
|
|
@@ -274,7 +332,7 @@
|
|
274
332
|
|
275
333
|
|
276
334
|
|
277
|
-
![イメージ説明](
|
335
|
+
![イメージ説明](45c264d3898b5c898a65408c0e7c901c.png)
|
278
336
|
|
279
337
|
|
280
338
|
|