質問編集履歴
4
説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,6 +23,10 @@
|
|
23
23
|
特に、述語(predicate) の使い方がわかりません。この場合どの述語を使えば良いのでしょうか?
|
24
24
|
|
25
25
|
特に、_gtの部分が適切かどうか、ご助言をお願いします。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
他の資料を見ると、「関連先のモデル名(複数)_関連先のカラム名_述語」という書き方をしなければならないとあり、それに従っていますが、これでいいのかもわかりません。
|
26
30
|
|
27
31
|
|
28
32
|
|
3
説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,12 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
特に、述語(predicate) の使い方がわかりません。この場合どの述語を使えば良いのでしょうか?
|
24
|
+
|
25
|
+
特に、_gtの部分が適切かどうか、ご助言をお願いします。
|
26
|
+
|
27
|
+
|
28
|
+
|
23
29
|
question_controller.rb
|
24
30
|
|
25
31
|
```ここに言語を入力
|
@@ -33,6 +39,8 @@
|
|
33
39
|
# 検索結果
|
34
40
|
|
35
41
|
@result = @search.result(distinct: true).order(created_at: :desc)
|
42
|
+
|
43
|
+
@answer_count = Question.joins(:answers).group("question_id").order('count(question_id) desc')
|
36
44
|
|
37
45
|
end
|
38
46
|
|
@@ -54,11 +62,11 @@
|
|
54
62
|
|
55
63
|
<div class="control">
|
56
64
|
|
57
|
-
<%= fa_icon "angle-right", class: "searchicon" %> <%= f.label :id_in, "回答数", class: "question-search-category" %><br>
|
65
|
+
<%= fa_icon "angle-right", class: "searchicon" %> <%= f.label :answers_question_id_in, "回答数", class: "question-search-category" %><br>
|
58
66
|
|
59
67
|
<div class="select is-fullwidth">
|
60
68
|
|
61
|
-
<%= f.select :
|
69
|
+
<%= f.select :answers_question_id_gt, [['回答数', @answer_count]], include_blank: "全てを選択" %>
|
62
70
|
|
63
71
|
</div>
|
64
72
|
|
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,11 +24,15 @@
|
|
24
24
|
|
25
25
|
```ここに言語を入力
|
26
26
|
|
27
|
-
def
|
27
|
+
def search
|
28
28
|
|
29
|
-
|
29
|
+
# 検索オブジェクト
|
30
30
|
|
31
|
+
@search = Question.ransack(params[:q])
|
32
|
+
|
33
|
+
# 検索結果
|
34
|
+
|
31
|
-
@
|
35
|
+
@result = @search.result(distinct: true).order(created_at: :desc)
|
32
36
|
|
33
37
|
end
|
34
38
|
|
1
説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,11 +20,31 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
question_controller.rb
|
24
|
+
|
25
|
+
```ここに言語を入力
|
26
|
+
|
27
|
+
def index
|
28
|
+
|
29
|
+
@fields = Field.all
|
30
|
+
|
31
|
+
@questions = Question.paginate(page: params[:page], per_page: 2).order(created_at: :desc)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
23
41
|
_search_form.html.erb
|
24
42
|
|
25
43
|
```ここに言語を入力
|
26
44
|
|
27
45
|
|
46
|
+
|
47
|
+
<%= search_form_for(@search, url: search_questions_path, method: :get) do |f| %>
|
28
48
|
|
29
49
|
<div class="field">
|
30
50
|
|
@@ -42,4 +62,6 @@
|
|
42
62
|
|
43
63
|
</div>
|
44
64
|
|
65
|
+
<% end %>
|
66
|
+
|
45
67
|
```
|