回答編集履歴
1
追記
test
CHANGED
@@ -15,3 +15,29 @@
|
|
15
15
|
なお、scopeとmethodの名前を同じにするとあまりよろしくないです
|
16
16
|
|
17
17
|
`if search != "";else;end` も scopeに取り込んでしまっては?
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
scope :search, -> (search_param = nil) {
|
24
|
+
|
25
|
+
if search_param
|
26
|
+
|
27
|
+
return if search_param.blank?
|
28
|
+
|
29
|
+
joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = posts.id AND action_text_rich_texts.record_type = 'Post'")
|
30
|
+
|
31
|
+
.where("action_text_rich_texts.body LIKE ? OR posts.title LIKE ? ", "%#{search_param}%", "%#{search_param}%")
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
else
|
36
|
+
|
37
|
+
all
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
```
|