質問編集履歴
1
ああ
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,138 +34,6 @@
|
|
34
34
|
|
35
35
|
現在は、口コミの星の平均avg(microposts.rate)を降順で出しています。
|
36
36
|
|
37
|
-
```rails
|
38
|
-
|
39
|
-
<% @foods.order("avg(microposts.rate) desc").each.with_index(params[:page].to_i) do |food,n| %>
|
40
|
-
|
41
|
-
```
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
```foodcontroller
|
46
|
-
|
47
|
-
@foods = Food.left_joins(:microposts).group("id")
|
48
|
-
|
49
|
-
@dogs = Dog.all
|
50
|
-
|
51
|
-
```
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
User table
|
56
|
-
|
57
|
-
|ID|name||
|
58
|
-
|
59
|
-
|:--|:--:|--:|
|
60
|
-
|
61
|
-
|30|admin||
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
Food table
|
66
|
-
|
67
|
-
|ID|name|rate|
|
68
|
-
|
69
|
-
|:--|:--:|--:|
|
70
|
-
|
71
|
-
|9|ドッグフード名||
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Dog table
|
76
|
-
|
77
|
-
|ID|name||
|
78
|
-
|
79
|
-
|:--|:--:|--:|
|
80
|
-
|
81
|
-
|4|トイプードル||
|
82
|
-
|
83
|
-
|5|ブルドック||
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
Micropost table
|
88
|
-
|
89
|
-
|id|content|user_id|rate|food_id|dog_id|
|
90
|
-
|
91
|
-
|:--|:--:|--:|
|
92
|
-
|
93
|
-
|1|愛犬がとても喜んで食べます。|30|3.5|9|4|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
```routes
|
98
|
-
|
99
|
-
https://www.dogfoody.jp/dogs/dog_id
|
100
|
-
|
101
|
-
```
|
102
|
-
|
103
|
-
```FoodModel
|
104
|
-
|
105
|
-
has_many :microposts
|
106
|
-
|
107
|
-
has_many :favorites
|
108
|
-
|
109
|
-
has_many :users, through: :favorites
|
110
|
-
|
111
|
-
validates :name, uniqueness: true
|
112
|
-
|
113
|
-
```
|
114
|
-
|
115
|
-
```MicropostModel
|
116
|
-
|
117
|
-
belongs_to :food
|
118
|
-
|
119
|
-
belongs_to :user
|
120
|
-
|
121
|
-
```
|
122
|
-
|
123
|
-
```UserModel
|
124
|
-
|
125
|
-
has_many :microposts, dependent: :destroy
|
126
|
-
|
127
|
-
has_many :foods
|
128
|
-
|
129
|
-
```
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
```migrate
|
134
|
-
|
135
|
-
User
|
136
|
-
|
137
|
-
t.string "name"
|
138
|
-
|
139
|
-
Micropost
|
140
|
-
|
141
|
-
t.text "content"
|
142
|
-
|
143
|
-
t.integer "user_id"
|
144
|
-
|
145
|
-
t.float "rate", default: 0.0, null: false
|
146
|
-
|
147
|
-
t.string "dog_id"
|
148
|
-
|
149
|
-
t.integer "food_id"
|
150
|
-
|
151
|
-
t.index ["food_id", "created_at"], name: "index_microposts_on_food_id_and_created_at"
|
152
|
-
|
153
|
-
t.index ["food_id"], name: "index_microposts_on_food_id"
|
154
|
-
|
155
|
-
t.index ["user_id", "created_at"], name: "index_microposts_on_user_id_and_created_at"
|
156
|
-
|
157
|
-
t.index ["user_id"], name: "index_microposts_on_user_id"
|
158
|
-
|
159
|
-
Food
|
160
|
-
|
161
|
-
t.string "name"
|
162
|
-
|
163
|
-
Dog
|
164
|
-
|
165
|
-
t.string "name"
|
166
|
-
|
167
|
-
t.string "image"
|
168
|
-
|
169
37
|
```
|
170
38
|
|
171
39
|
|