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

質問編集履歴

1

modelの追加

2020/08/15 02:50

投稿

miSaito
miSaito

スコア16

title CHANGED
File without changes
body CHANGED
@@ -30,4 +30,28 @@
30
30
  price_service: サービス名
31
31
  price_service: 値段
32
32
 
33
+ ```
34
+
35
+ ```
36
+ #priceモデル
37
+
38
+ class Price < ApplicationRecord
39
+
40
+ belongs_to :person, optional: true
41
+
42
+ validates :service, :price, presence: true
43
+ validates :service, length: { maximum: 30 }
44
+
45
+ end
46
+
47
+ #personモデル
48
+
49
+ class Person < ApplicationRecord
50
+
51
+ has_many :prices, dependent: :destroy
52
+ accepts_nested_attributes_for :prices, allow_destroy: true
53
+
54
+ validates :name, :gender, :contact, :sample, :comment, presence: true
55
+
56
+ end
33
57
  ```