質問編集履歴
3
Error追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -158,13 +158,13 @@
|
|
158
158
|
|
159
159
|
tr
|
160
160
|
|
161
|
-
td = area.restaurant.restaurant_type
|
161
|
+
td = area.restaurants.restaurant_type
|
162
162
|
|
163
|
-
td = link_to area.restaurant.restaurant_translations.with_lang.first.restaurantname, (url_for controller:'restaurant', trailing_slash: true) + area.restaurant.id.to_s
|
163
|
+
td = link_to area.restaurants.restaurant_translations.with_lang.first.restaurantname, (url_for controller:'restaurant', trailing_slash: true) + area.restaurants.id.to_s
|
164
164
|
|
165
|
-
td = link_to 'official', area.restaurant.url
|
165
|
+
td = link_to 'official', area.restaurants.url
|
166
166
|
|
167
|
-
td = area.restaurant.genre
|
167
|
+
td = area.restaurants.genre
|
168
168
|
|
169
169
|
```
|
170
170
|
|
@@ -172,4 +172,4 @@
|
|
172
172
|
|
173
173
|
Error内容はこちらです。
|
174
174
|
|
175
|
-
![イメージ説明](
|
175
|
+
![イメージ説明](ad6fd5c8195458ade768186f23ceb652.png)
|
2
Error表示追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -167,3 +167,9 @@
|
|
167
167
|
td = area.restaurant.genre
|
168
168
|
|
169
169
|
```
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
Error内容はこちらです。
|
174
|
+
|
175
|
+
![イメージ説明](b06993342030071c7a49ed2d0a1ef6e6.png)
|
1
ソース追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,3 +19,151 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
Areaテーブルのid=1に紐づくRestaurantTranslationの情報(例:restaurantname)を取得するにはどのようにしたらいいでしょうか?
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
【追記】
|
26
|
+
|
27
|
+
実はErrorが出ていて、
|
28
|
+
|
29
|
+
Association named 'restaurant_translations' was not found on Area; perhaps you misspelled it?
|
30
|
+
|
31
|
+
となってしまいます。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
URLでIDを指定しているので、それに紐付いたrestaurantとrestaurant情報が全部出力したい感じです。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
ソースを提示します。Controllerはこちらです。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
|
45
|
+
class AreaController < ApplicationController
|
46
|
+
|
47
|
+
def index
|
48
|
+
|
49
|
+
@areas = Area.all
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def show
|
56
|
+
|
57
|
+
@areas = Area.includes(:area_translations, :restaurants, :restaurant_translations).where(id: params[:id])
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
Modelはこちらです。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
|
73
|
+
class Area < ActiveRecord::Base
|
74
|
+
|
75
|
+
has_many :area_translations
|
76
|
+
|
77
|
+
has_many :restaurants
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
class Restaurant < ActiveRecord::Base
|
84
|
+
|
85
|
+
has_many :restaurant_translations
|
86
|
+
|
87
|
+
has_many :menus
|
88
|
+
|
89
|
+
has_many :reviews
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
belongs_to :areas
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
class RestaurantTranslation < ActiveRecord::Base
|
102
|
+
|
103
|
+
self.table_name = 'restaurant_translations'
|
104
|
+
|
105
|
+
belongs_to :restaurants
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
scope :with_lang , -> { where(lang: I18n.locale )}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
class AreaTranslation < ActiveRecord::Base
|
118
|
+
|
119
|
+
belongs_to :areas
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
scope :with_lang , -> { where(lang: I18n.locale )}
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
View(slim)はこちらです。
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
|
141
|
+
table
|
142
|
+
|
143
|
+
thead
|
144
|
+
|
145
|
+
tr
|
146
|
+
|
147
|
+
th = t :restaurant_list_type
|
148
|
+
|
149
|
+
th = t :restaurant_list_name
|
150
|
+
|
151
|
+
th = t :restaurant_list_url
|
152
|
+
|
153
|
+
th = t :restaurant_list_genre
|
154
|
+
|
155
|
+
tbody
|
156
|
+
|
157
|
+
- @areas.each do |area|
|
158
|
+
|
159
|
+
tr
|
160
|
+
|
161
|
+
td = area.restaurant.restaurant_type
|
162
|
+
|
163
|
+
td = link_to area.restaurant.restaurant_translations.with_lang.first.restaurantname, (url_for controller:'restaurant', trailing_slash: true) + area.restaurant.id.to_s
|
164
|
+
|
165
|
+
td = link_to 'official', area.restaurant.url
|
166
|
+
|
167
|
+
td = area.restaurant.genre
|
168
|
+
|
169
|
+
```
|