質問編集履歴

4

コード変更

2018/05/29 04:36

投稿

koichi8888
koichi8888

スコア24

test CHANGED
File without changes
test CHANGED
@@ -108,7 +108,7 @@
108
108
 
109
109
  ### 該当のソースコード
110
110
 
111
- \config\schedule.rb
111
+ /config/schedule.rb
112
112
 
113
113
  ```Ruby
114
114
 
@@ -200,7 +200,7 @@
200
200
 
201
201
  ```
202
202
 
203
- \lib\mail_notice.rb
203
+ /lib/mail_notice.rb
204
204
 
205
205
  ```Ruby
206
206
 

3

コード追加

2018/05/29 04:36

投稿

koichi8888
koichi8888

スコア24

test CHANGED
File without changes
test CHANGED
@@ -108,7 +108,7 @@
108
108
 
109
109
  ### 該当のソースコード
110
110
 
111
- <アプリroot>\config\schedule.rb
111
+ \config\schedule.rb
112
112
 
113
113
  ```Ruby
114
114
 
@@ -200,7 +200,7 @@
200
200
 
201
201
  ```
202
202
 
203
- <アプリroot>\lib\mail_notice.rb
203
+ \lib\mail_notice.rb
204
204
 
205
205
  ```Ruby
206
206
 
@@ -246,6 +246,214 @@
246
246
 
247
247
  ```
248
248
 
249
+ app/controllers/items_controller.rb
250
+
251
+
252
+
253
+ ```Ruby
254
+
255
+ class ItemsController < ApplicationController
256
+
257
+
258
+
259
+ before_action :authenticate_user
260
+
261
+
262
+
263
+
264
+
265
+ def index
266
+
267
+
268
+
269
+
270
+
271
+ # データを降順で表示する
272
+
273
+ @items = GyomuDatum.all.order(created_at: 'desc')
274
+
275
+
276
+
277
+
278
+
279
+ # 期限が迫っているデータを検索する
280
+
281
+
282
+
283
+ # 1ヶ月前
284
+
285
+ from = Time.now.at_beginning_of_day
286
+
287
+ to = (from + 1.month)
288
+
289
+ @items_1month = GyomuDatum.where(end_date: from...to)
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+ end
298
+
299
+
300
+
301
+ def show
302
+
303
+ end
304
+
305
+
306
+
307
+ def new
308
+
309
+ @item = GyomuDatum.new
310
+
311
+ end
312
+
313
+
314
+
315
+ def create
316
+
317
+ # render plain: params[:GyomuDatum].inspect
318
+
319
+ # save
320
+
321
+ # @item = Item.new(params[:GyomuDatum])
322
+
323
+ # @item = GyomuDatum.new(params.require(:GyomuDatum).permit(:manage_id, :category_id, :publish_corporation, :ip_address, :target_server, :start_date, :end_date, :comment))
324
+
325
+ @item = GyomuDatum.new(item_params)
326
+
327
+ # @item.save
328
+
329
+ # redirect
330
+
331
+ # redirect_to items_path
332
+
333
+
334
+
335
+ if @item.save
336
+
337
+ # redirect
338
+
339
+ redirect_to items_path
340
+
341
+ else
342
+
343
+ # render plain: @item.errors.inspect
344
+
345
+ render 'new'
346
+
347
+ end
348
+
349
+ end
350
+
351
+
352
+
353
+
354
+
355
+ def edit
356
+
357
+ @item = GyomuDatum.find(params[:id])
358
+
359
+ end
360
+
361
+
362
+
363
+ def update
364
+
365
+ @item = GyomuDatum.find(params[:id])
366
+
367
+ # pp @item
368
+
369
+ # pp item_params
370
+
371
+
372
+
373
+ if @item.update(item_params)
374
+
375
+ redirect_to items_path
376
+
377
+ else
378
+
379
+ render 'edit'
380
+
381
+ end
382
+
383
+ end
384
+
385
+
386
+
387
+ def destroy
388
+
389
+ @item = GyomuDatum.find(params[:id])
390
+
391
+ @item.destroy
392
+
393
+ redirect_to items_path
394
+
395
+ end
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+ # cron用メール送信メソッド
404
+
405
+ def mail_notice
406
+
407
+
408
+
409
+ # メール送信実行
410
+
411
+ SampleMailer.send_when_limit.deliver
412
+
413
+
414
+
415
+ end
416
+
417
+
418
+
419
+
420
+
421
+ private
422
+
423
+ def item_params
424
+
425
+ permits = [
426
+
427
+ :manage_id,
428
+
429
+ :category_id,
430
+
431
+ :publish_corporation,
432
+
433
+ :ip_address,
434
+
435
+ :target_server,
436
+
437
+ :start_date,
438
+
439
+ :end_date,
440
+
441
+ :comment
442
+
443
+ ]
444
+
445
+ params.require(:gyomu_datum).permit(permits)
446
+
447
+ end
448
+
449
+
450
+
451
+
452
+
453
+ end
454
+
455
+ ```
456
+
249
457
  ### 試したこと
250
458
 
251
459
 

2

コード追加

2018/05/29 04:35

投稿

koichi8888
koichi8888

スコア24

test CHANGED
File without changes
test CHANGED
@@ -218,6 +218,34 @@
218
218
 
219
219
 
220
220
 
221
+ 更新、動作確認の出力
222
+
223
+ ```Ruby
224
+
225
+ [root@localhost Myapp]# bundle exec whenever --update-crontab
226
+
227
+ [write] crontab file updated
228
+
229
+ [root@localhost Myapp]# crontab -l
230
+
231
+ # Begin Whenever generated tasks for: /Myapp/config/schedule.rb at: 2018-05-29 13:25:56 +0900
232
+
233
+ * * * * * /bin/bash -l -c 'echo '\''hello, whenever world!'\'' >> log/crontab.log 2>&1'
234
+
235
+
236
+
237
+ * * * * * /bin/bash -l -c 'cd /Myapp && bundle exec bin/rails runner -e production '\''items_controller.mail_notice'\'' >> log/crontab.log 2>&1'
238
+
239
+
240
+
241
+ * * * * * /bin/bash -l -c 'cd /Myapp && bundle exec bin/rails runner -e production '\''Tasks::Mailnotice.execute'\'' >> log/crontab.log 2>&1'
242
+
243
+
244
+
245
+ # End Whenever generated tasks for: /Myapp/config/schedule.rb at: 2018-05-29 13:25:56 +0900
246
+
247
+ ```
248
+
221
249
  ### 試したこと
222
250
 
223
251
 

1

記載変更

2018/05/29 04:28

投稿

koichi8888
koichi8888

スコア24

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,9 @@
10
10
 
11
11
 
12
12
 
13
- 動作確認として、タスクを手動実行したところ、エラーが表示され、困っています。
13
+ 動作確認として、タスクを手動実行したところ、エラーが表示され、エラー内容としてはクラスがうまく読み込めていない旨のメッセージが表示されているのですが、つづりは合っており、対応に困っています。
14
+
15
+ 何かご存知のことがございましたら、ご教示頂けると助かります。
14
16
 
15
17
 
16
18