質問編集履歴
2
カテゴリーモデル追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -274,4 +274,70 @@
|
|
274
274
|
|
275
275
|
</div>
|
276
276
|
|
277
|
+
```Category モデル
|
278
|
+
|
279
|
+
```ここに言語を入力
|
280
|
+
|
281
|
+
class Category < ActiveHash::Base
|
282
|
+
|
283
|
+
self.data = [
|
284
|
+
|
285
|
+
{ id: 1, name: '--' },
|
286
|
+
|
287
|
+
{ id: 2, name: '初詣・新年会'},
|
288
|
+
|
289
|
+
{ id: 3, name: '節分'},
|
290
|
+
|
291
|
+
{ id: 4, name: 'ひな祭り'},
|
292
|
+
|
293
|
+
{ id: 5, name: 'お花見'},
|
294
|
+
|
295
|
+
{ id: 6, name: '端午の節句'},
|
296
|
+
|
297
|
+
{ id: 7, name: '母の日'},
|
298
|
+
|
299
|
+
{ id: 8, name: '父の日'},
|
300
|
+
|
301
|
+
{ id: 9, name: '七夕'},
|
302
|
+
|
303
|
+
{ id: 10, name: '夏祭り'},
|
304
|
+
|
305
|
+
{ id: 11, name: '十五夜'},
|
306
|
+
|
307
|
+
{ id: 12, name: '敬老の日'},
|
308
|
+
|
309
|
+
{ id: 13, name: '運動会'},
|
310
|
+
|
311
|
+
{ id: 14, name: '紅葉狩り'},
|
312
|
+
|
313
|
+
{ id: 15, name: 'クリスマス会'},
|
314
|
+
|
315
|
+
{ id: 16, name: '年越し'},
|
316
|
+
|
317
|
+
{ id: 17, name: '誕生日会'},
|
318
|
+
|
319
|
+
{ id: 18, name: '音楽会'},
|
320
|
+
|
321
|
+
{ id: 19, name: '食事関連'},
|
322
|
+
|
323
|
+
{ id: 20, name: '外出'},
|
324
|
+
|
325
|
+
{ id: 21, name: 'その他'}
|
326
|
+
|
327
|
+
]
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
include ActiveHash::Associations
|
332
|
+
|
333
|
+
has_many :events
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
|
277
343
|
```
|
1
修正後のエラー追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -225,3 +225,53 @@
|
|
225
225
|
end
|
226
226
|
|
227
227
|
```eventモデルのnameとtagモデルのtagnameは検索することができましたがアクティブハッシュの検索がどうしてもできません。何か方法がありましたらお願い致します
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
### 修正(行ったこと)
|
232
|
+
|
233
|
+
```ここに言語を入力
|
234
|
+
|
235
|
+
def self.search(search)
|
236
|
+
|
237
|
+
if search != ""
|
238
|
+
|
239
|
+
Event.joins(:tags, :category).where(['event.name LIKE ? OR tagname LIKE ? categories.name LIKE ?', "%#{search}%", "%#{search}%", "%#{search}%"])
|
240
|
+
|
241
|
+
else
|
242
|
+
|
243
|
+
Event.all
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
```エラー文
|
250
|
+
|
251
|
+
```ここに言語を入力
|
252
|
+
|
253
|
+
NoMethodError in Events#search_event
|
254
|
+
|
255
|
+
Showing /Users/user/projects/asomemo/app/views/events/search_event.html.erb where line #6 raised:
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
undefined method `table_name' for Category:Class
|
260
|
+
|
261
|
+
Extracted source (around line #6):
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
<% end %>
|
266
|
+
|
267
|
+
<div class="contents row">
|
268
|
+
|
269
|
+
<% @events.each do |event| %>
|
270
|
+
|
271
|
+
<%= render partial: "event", locals: { event: event } %>
|
272
|
+
|
273
|
+
<% end %>
|
274
|
+
|
275
|
+
</div>
|
276
|
+
|
277
|
+
```
|