質問編集履歴

2

誤字脱字

2020/10/20 05:26

投稿

Airi.
Airi.

スコア8

test CHANGED
File without changes
test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  ### 該当のソースコード
46
46
 
47
- > **ルーティング**
47
+ > **ルーティング**
48
48
 
49
49
  ```Ruby
50
50
 
@@ -70,6 +70,52 @@
70
70
 
71
71
  ```
72
72
 
73
+ > **モデル: recipe.rb**
74
+
75
+ ```Ruby
76
+
77
+ class Recipe < ApplicationRecord
78
+
79
+ extend ActiveHash::Associations::ActiveRecordExtensions
80
+
81
+ belongs_to_active_hash :category
82
+
83
+
84
+
85
+ mount_uploader :image, ImageUploader
86
+
87
+ belongs_to :user
88
+
89
+ has_many :ingredients
90
+
91
+ accepts_nested_attributes_for :ingredients, allow_destroy: true
92
+
93
+
94
+
95
+ with_options presence: true do
96
+
97
+ validates :user_id
98
+
99
+ validates :title
100
+
101
+ validates :eat
102
+
103
+ validates :category_id, numericality: { other_than: 1, message: "を選択してください" }
104
+
105
+ validates :time, format: {with: /\d/}
106
+
107
+ #validates :recipe_id
108
+
109
+ validates :thing_id
110
+
111
+ validates :amount
112
+
113
+ end
114
+
115
+ end
116
+
117
+ ```
118
+
73
119
  > **コントローラー:recipe_controller.rb**
74
120
 
75
121
  ```Ruby
@@ -130,52 +176,6 @@
130
176
 
131
177
  ```
132
178
 
133
- > **モデル: recipe.rb**
134
-
135
- ```Ruby
136
-
137
- class Recipe < ApplicationRecord
138
-
139
- extend ActiveHash::Associations::ActiveRecordExtensions
140
-
141
- belongs_to_active_hash :category
142
-
143
-
144
-
145
- mount_uploader :image, ImageUploader
146
-
147
- belongs_to :user
148
-
149
- has_many :ingredients
150
-
151
- accepts_nested_attributes_for :ingredients, allow_destroy: true
152
-
153
-
154
-
155
- with_options presence: true do
156
-
157
- validates :user_id
158
-
159
- validates :title
160
-
161
- validates :eat
162
-
163
- validates :category_id, numericality: { other_than: 1, message: "を選択してください" }
164
-
165
- validates :time, format: {with: /\d/}
166
-
167
- #validates :recipe_id
168
-
169
- validates :thing_id
170
-
171
- validates :amount
172
-
173
- end
174
-
175
- end
176
-
177
- ```
178
-
179
179
  > **ビュー: recipes/new.html.erb (該当箇所のみ)**
180
180
 
181
181
  ```HTML.erb

1

ルーティングを追加しました。

2020/10/20 05:26

投稿

Airi.
Airi.

スコア8

test CHANGED
File without changes
test CHANGED
@@ -44,7 +44,31 @@
44
44
 
45
45
  ### 該当のソースコード
46
46
 
47
-
47
+ > **ルーティングー**
48
+
49
+ ```Ruby
50
+
51
+ Rails.application.routes.draw do
52
+
53
+ devise_for :users
54
+
55
+ root to: 'recipes#new'
56
+
57
+ resources :users
58
+
59
+ resources :recipes do
60
+
61
+ resources :ingredients
62
+
63
+ end
64
+
65
+ resources :things
66
+
67
+ end
68
+
69
+
70
+
71
+ ```
48
72
 
49
73
  > **コントローラー:recipe_controller.rb**
50
74