質問編集履歴

3

誤字

2020/09/25 05:25

投稿

jun3030
jun3030

スコア16

test CHANGED
File without changes
test CHANGED
@@ -166,7 +166,7 @@
166
166
 
167
167
     # マッサージ師が持っている出張範囲で検索が出来ない
168
168
 
169
- <%= f.collection_select :masseurs_business_trip_ranges_cities_city_name_cont, Prefecture.all, :name, :name %>
169
+ <%= f.collection_select :masseurs_business_trip_ranges_cities_city_name_cont, City.all, :name, :name %>
170
170
 
171
171
 
172
172
 

2

解答者様への補足情報

2020/09/25 05:25

投稿

jun3030
jun3030

スコア16

test CHANGED
File without changes
test CHANGED
@@ -88,4 +88,122 @@
88
88
 
89
89
 
90
90
 
91
- ここにより詳細情報を記載てくださ
91
+ お返事遅くって申し訳ありません汗
92
+
93
+ モデル関係がややこしいのでER図も添えました。
94
+
95
+
96
+
97
+ 今回具体的にやろうとしたいのが、お店(storeモデル)に所属しているマッサージ師の出張範囲を市町村(Cityモデル)の名前(city_nameカラム)から検索したいというものです。
98
+
99
+ 今のところお店の名前では検索出来るようになっているのですが、そこからネストされたモデルのカラムから検索する事が出来ないでいます汗
100
+
101
+
102
+
103
+ modelの関係性
104
+
105
+ ```
106
+
107
+
108
+
109
+ Store
110
+
111
+ has_many :masseurs, dependent: :destroy
112
+
113
+
114
+
115
+ Masseur
116
+
117
+ has_many :business_trip_ranges, dependent: :delete_all
118
+
119
+ has_many :cities, through: :business_trip_ranges
120
+
121
+
122
+
123
+ BusinessTripRange
124
+
125
+ belongs_to :masseur
126
+
127
+ belongs_to :city
128
+
129
+
130
+
131
+ City
132
+
133
+ has_many :masseurs, through: :business_trip_ranges
134
+
135
+ has_many :business_trip_ranges
136
+
137
+
138
+
139
+ Prefecture
140
+
141
+ has_many :cities, dependent: :delete_all
142
+
143
+ ```
144
+
145
+
146
+
147
+ ![イメージ説明](7fc3ac5bc8d1b013fd1f2e326c5cc7be.png)
148
+
149
+
150
+
151
+ ```
152
+
153
+ shop.html.erb
154
+
155
+
156
+
157
+ <%= search_form_for @search, url: shop_path do |f| %>
158
+
159
+    # storeの名前で検索は出来る
160
+
161
+ <%= f.label :store_name_cont, '名前' %>
162
+
163
+ <%= f.search_field :store_name_cont %>
164
+
165
+    
166
+
167
+    # マッサージ師が持っている出張範囲で検索が出来ない
168
+
169
+ <%= f.collection_select :masseurs_business_trip_ranges_cities_city_name_cont, Prefecture.all, :name, :name %>
170
+
171
+
172
+
173
+
174
+
175
+ <%= f.submit '検索' %>
176
+
177
+ <% end %>
178
+
179
+
180
+
181
+
182
+
183
+ <% @store_result.each do |store| %>
184
+
185
+ <%= store.store_name %>
186
+
187
+ <% end %>
188
+
189
+ ```
190
+
191
+
192
+
193
+ ```
194
+
195
+ shop_controller
196
+
197
+
198
+
199
+ def shop
200
+
201
+ # マッサージ師の検索機能
202
+
203
+ @search = Store.ransack(params[:q])
204
+
205
+ @store_result = @search.result
206
+
207
+ end
208
+
209
+ ```

1

誤字

2020/09/25 05:22

投稿

jun3030
jun3030

スコア16

test CHANGED
File without changes
test CHANGED
@@ -54,7 +54,7 @@
54
54
 
55
55
  = f.text_field :area_staff_name_cont
56
56
 
57
- # shopモデルに紐づくareaモデルのnameカラム(staffの名前)でデータがないか検索
57
+ # shopモデルに紐づくareaモデルに紐づくstaffモデルのnameカラム(staffの名前)でデータがないか検索
58
58
 
59
59
 
60
60