質問するログイン新規登録

質問編集履歴

7

修正

2019/07/30 05:09

投稿

ssk
ssk

スコア332

title CHANGED
File without changes
body CHANGED
@@ -55,7 +55,7 @@
55
55
  extend ActiveSupport::Concern
56
56
 
57
57
  included do
58
- before_create -> { update_progress('payment') }
58
+ after_create -> { update_progress('payment') }
59
59
  validate :check_combination_status
60
60
  end
61
61
 

6

修正

2019/07/30 05:09

投稿

ssk
ssk

スコア332

title CHANGED
File without changes
body CHANGED
@@ -55,7 +55,7 @@
55
55
  extend ActiveSupport::Concern
56
56
 
57
57
  included do
58
- before_save -> { update_progress('payment') }
58
+ before_create -> { update_progress('payment') }
59
59
  validate :check_combination_status
60
60
  end
61
61
 
@@ -67,7 +67,7 @@
67
67
 
68
68
  def check_combination_status
69
69
  return if number.blank?
70
- wf = Workflow.where(number: number
70
+ wf = Workflow.where(number: number)
71
71
  unless wf.all? { |w| Status.find_by(compensation: w.compensation progress: progress).present? }
72
72
  errors[:base] << 'エラーメッセージ'
73
73
  end

5

修正

2019/07/30 05:08

投稿

ssk
ssk

スコア332

title CHANGED
File without changes
body CHANGED
@@ -51,7 +51,7 @@
51
51
 
52
52
  # 追記2
53
53
  ```ruby
54
- module AccidentProgressUpdateble
54
+ module ProgressUpdateble
55
55
  extend ActiveSupport::Concern
56
56
 
57
57
  included do

4

追記

2019/07/30 04:52

投稿

ssk
ssk

スコア332

title CHANGED
File without changes
body CHANGED
@@ -47,4 +47,31 @@
47
47
  end
48
48
  end
49
49
 
50
+ ```
51
+
52
+ # 追記2
53
+ ```ruby
54
+ module AccidentProgressUpdateble
55
+ extend ActiveSupport::Concern
56
+
57
+ included do
58
+ before_save -> { update_progress('payment') }
59
+ validate :check_combination_status
60
+ end
61
+
62
+ def update_progress(status)
63
+ return if number.blank?
64
+ w = Workflow.where(approval_status: 'pending', number: number)
65
+ w.update_all(progress: status)
66
+ end
67
+
68
+ def check_combination_status
69
+ return if number.blank?
70
+ wf = Workflow.where(number: number
71
+ unless wf.all? { |w| Status.find_by(compensation: w.compensation progress: progress).present? }
72
+ errors[:base] << 'エラーメッセージ'
73
+ end
74
+ end
75
+ end
76
+
50
77
  ```

3

修正

2019/07/30 04:50

投稿

ssk
ssk

スコア332

title CHANGED
File without changes
body CHANGED
@@ -39,11 +39,11 @@
39
39
  attr_accessor :compensation :progress, :status
40
40
 
41
41
  def self.find_by(compensation:, progress:)
42
- ACCIDENT_STATUS_MANAGER.find_by(compensation: compensation, progress: progress)
42
+ STATUS_MANAGER.find_by(compensation: compensation, progress: progress)
43
43
  end
44
44
 
45
45
  def self.statuses
46
- ACCIDENT_STATUS_MANAGER.statuses
46
+ STATUS_MANAGER.statuses
47
47
  end
48
48
  end
49
49
 

2

追記

2019/07/30 03:45

投稿

ssk
ssk

スコア332

title CHANGED
File without changes
body CHANGED
@@ -30,4 +30,21 @@
30
30
 
31
31
  ### 補足情報(FW/ツールのバージョンなど)
32
32
  ・Rails 5.1.7
33
- ・Ruby 2.6.3
33
+ ・Ruby 2.6.3
34
+
35
+ # 追記
36
+ ```ruby
37
+ StatusはCSVファイルをnewしてモデルのように扱っています。
38
+ class Status
39
+ attr_accessor :compensation :progress, :status
40
+
41
+ def self.find_by(compensation:, progress:)
42
+ ACCIDENT_STATUS_MANAGER.find_by(compensation: compensation, progress: progress)
43
+ end
44
+
45
+ def self.statuses
46
+ ACCIDENT_STATUS_MANAGER.statuses
47
+ end
48
+ end
49
+
50
+ ```

1

追記

2019/07/30 03:43

投稿

ssk
ssk

スコア332

title CHANGED
File without changes
body CHANGED
@@ -5,7 +5,11 @@
5
5
  ### 該当のソースコード・試したこと
6
6
  やりたいことを伝えるための雰囲気でのコードになりますが、以下のようなイメージです。
7
7
  ```ruby
8
+ def Workflow < ApplicationRecord
9
+
10
+ before_save -> { update_accident_progress('payment') }
11
+
8
- def update_progress(status)
12
+ def update_progress(status)
9
13
  return if number.blank? # numberがなければリターン
10
14
 
11
15
  wf = Workflow.where(number: number)
@@ -19,6 +23,7 @@
19
23
  else
20
24
  errors[:base] << 'ダメです。'
21
25
  end
26
+ end
22
27
  end
23
28
  ```
24
29