質問編集履歴
2
誤字脱字
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
作成済みのテーブルが????マークがついているものです。
|
22
22
|
|
23
23
|
### 該当のソースコード
|
24
|
-
> **ルーティング
|
24
|
+
> **ルーティング**
|
25
25
|
```Ruby
|
26
26
|
Rails.application.routes.draw do
|
27
27
|
devise_for :users
|
@@ -34,6 +34,29 @@
|
|
34
34
|
end
|
35
35
|
|
36
36
|
```
|
37
|
+
> **モデル: recipe.rb**
|
38
|
+
```Ruby
|
39
|
+
class Recipe < ApplicationRecord
|
40
|
+
extend ActiveHash::Associations::ActiveRecordExtensions
|
41
|
+
belongs_to_active_hash :category
|
42
|
+
|
43
|
+
mount_uploader :image, ImageUploader
|
44
|
+
belongs_to :user
|
45
|
+
has_many :ingredients
|
46
|
+
accepts_nested_attributes_for :ingredients, allow_destroy: true
|
47
|
+
|
48
|
+
with_options presence: true do
|
49
|
+
validates :user_id
|
50
|
+
validates :title
|
51
|
+
validates :eat
|
52
|
+
validates :category_id, numericality: { other_than: 1, message: "を選択してください" }
|
53
|
+
validates :time, format: {with: /\d/}
|
54
|
+
#validates :recipe_id
|
55
|
+
validates :thing_id
|
56
|
+
validates :amount
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
37
60
|
> **コントローラー:recipe_controller.rb**
|
38
61
|
```Ruby
|
39
62
|
class RecipesController < ApplicationController
|
@@ -64,29 +87,6 @@
|
|
64
87
|
end
|
65
88
|
end
|
66
89
|
```
|
67
|
-
> **モデル: recipe.rb**
|
68
|
-
```Ruby
|
69
|
-
class Recipe < ApplicationRecord
|
70
|
-
extend ActiveHash::Associations::ActiveRecordExtensions
|
71
|
-
belongs_to_active_hash :category
|
72
|
-
|
73
|
-
mount_uploader :image, ImageUploader
|
74
|
-
belongs_to :user
|
75
|
-
has_many :ingredients
|
76
|
-
accepts_nested_attributes_for :ingredients, allow_destroy: true
|
77
|
-
|
78
|
-
with_options presence: true do
|
79
|
-
validates :user_id
|
80
|
-
validates :title
|
81
|
-
validates :eat
|
82
|
-
validates :category_id, numericality: { other_than: 1, message: "を選択してください" }
|
83
|
-
validates :time, format: {with: /\d/}
|
84
|
-
#validates :recipe_id
|
85
|
-
validates :thing_id
|
86
|
-
validates :amount
|
87
|
-
end
|
88
|
-
end
|
89
|
-
```
|
90
90
|
> **ビュー: recipes/new.html.erb (該当箇所のみ)**
|
91
91
|
```HTML.erb
|
92
92
|
<%#材料%>
|
1
ルーティングを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,7 +21,19 @@
|
|
21
21
|
作成済みのテーブルが????マークがついているものです。
|
22
22
|
|
23
23
|
### 該当のソースコード
|
24
|
+
> **ルーティングー**
|
25
|
+
```Ruby
|
26
|
+
Rails.application.routes.draw do
|
27
|
+
devise_for :users
|
28
|
+
root to: 'recipes#new'
|
29
|
+
resources :users
|
30
|
+
resources :recipes do
|
31
|
+
resources :ingredients
|
32
|
+
end
|
33
|
+
resources :things
|
34
|
+
end
|
24
35
|
|
36
|
+
```
|
25
37
|
> **コントローラー:recipe_controller.rb**
|
26
38
|
```Ruby
|
27
39
|
class RecipesController < ApplicationController
|