teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追記

2020/09/28 08:01

投稿

winterboum
winterboum

スコア23654

answer CHANGED
@@ -27,4 +27,16 @@
27
27
  offices += Office.where(。。。)
28
28
  end
29
29
  end
30
- ```
30
+ ```
31
+
32
+ 追記
33
+ pagy は使ったことがないのですが
34
+ ```
35
+ elsif params[:keyword]
36
+ keywords = params[:keyword].split(/[[:blank:]]+/).select(&:present?)
37
+ relation = like_(keywords.shift)
38
+ keywords.each{ |keyword| relation.or(like_keyword) }
39
+ pagy, offices = pagy relation
40
+ else
41
+ ```
42
+ かな

1

修正

2020/09/28 08:01

投稿

winterboum
winterboum

スコア23654

answer CHANGED
@@ -8,4 +8,23 @@
8
8
  keywords.each do |keyword|
9
9
  Office.where(。。。)
10
10
  ```
11
- としましょう
11
+ としましょう
12
+ 訂正
13
+ ```
14
+ def search_office_from_keyword(keywords)
15
+ offices = []
16
+ keywords.each do |keyword|
17
+ offices += Office.where(。。。)
18
+ end
19
+ offices
20
+ end
21
+ ```
22
+ でした。
23
+ もしくは
24
+ ```
25
+ def search_office_from_keyword(keywords)
26
+ keywords.each_with_object([]) do |keyword,offices|
27
+ offices += Office.where(。。。)
28
+ end
29
+ end
30
+ ```