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

質問編集履歴

5

scss追加

2020/10/31 13:40

投稿

Zengo_Master
Zengo_Master

スコア19

title CHANGED
File without changes
body CHANGED
@@ -235,6 +235,62 @@
235
235
  </div>
236
236
  ```
237
237
 
238
+ app/assets/stylesheets/index.scss
239
+ ```scss
240
+ .index-wrapper {
241
+ margin: 20px;
242
+ }
243
+
244
+ .new-link {
245
+ font-size: 20px;
246
+ }
247
+
248
+ h2 {
249
+ margin-top: 20px;
250
+ }
251
+
252
+ .search-form {
253
+ margin: 5px 0px;
254
+ }
255
+
256
+ .selection-field {
257
+ margin-bottom: 5px;
258
+ }
259
+
260
+ .kifu-lists {
261
+ width: 550px;
262
+ margin-top: 5px;
263
+ }
264
+
265
+ .one-kifu {
266
+ padding: 5px;
267
+ margin-bottom: 5px;
268
+ border: 1px solid black;
269
+ font-size: 20px;
270
+ position: relative;
271
+ }
272
+
273
+ .opponent {
274
+ left: 150px;
275
+ position: absolute;
276
+ }
277
+
278
+ .result {
279
+ left: 250px;
280
+ position: absolute;
281
+ }
282
+
283
+ .type {
284
+ left: 300px;
285
+ position: absolute;
286
+ }
287
+
288
+ .kifu-page {
289
+ right: 10px;
290
+ position: absolute;
291
+ }
292
+ ```
293
+
238
294
  app/views/kifus/search.html.erb
239
295
  ```html
240
296
  // indexと同じコード

4

検索の画面を追加しました

2020/10/31 13:40

投稿

Zengo_Master
Zengo_Master

スコア19

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  # 複数条件の検索機能
2
2
  indexで表示されているデータに、複数の検索をかけて絞り込みたいです。現在は、ひとつの条件だけ検索できる状態です。
3
3
 
4
- ![イメージ説明](3e836baab12a6b5f1f0697a10f3ae56c.png)
4
+ ![イメージ説明](f2fdfa053e3d017c2aa710f58302784a.png)
5
5
 
6
6
  Active_Hashを利用しているデータもあり、それらはプルダウンでの検索を望んでいます。
7
7
  以下は、現在の状態です。

3

検索機能の実装

2020/10/31 13:34

投稿

Zengo_Master
Zengo_Master

スコア19

title CHANGED
File without changes
body CHANGED
@@ -32,11 +32,12 @@
32
32
 
33
33
  def self.search(search)
34
34
  if search != ""
35
- Kifu.where('opponent LIKE(?)', "%#{search}%")
35
+ Kifu.where('opponent LIKE(?)', "%#{search[:keyword]}%").where(result_id: search[:result]).where(type_id: search[:type])
36
36
  else
37
37
  Kifu.all
38
38
  end
39
39
  end
40
+
40
41
  end
41
42
  ```
42
43
 
@@ -153,7 +154,7 @@
153
154
  end
154
155
 
155
156
  def search
156
- @kifus = Kifu.search(params[:keyword])
157
+ @kifus = Kifu.search(params)
157
158
  end
158
159
 
159
160
  private
@@ -179,11 +180,24 @@
179
180
 
180
181
  <h2><棋譜検索></h2>
181
182
  <%= form_with(url: search_kifus_path, local: true, method: :get, class: "search-form") do |f| %>
182
- <%= f.label :date, '相手:' %>
183
- <%= f.text_field :keyword, placeholder: "", class: "search-input" %>
184
- <%= f.submit "検索", class: "search-btn" %>
185
- <% end %>
186
183
 
184
+ <div class="selection-field">
185
+ <%= f.label :opponent, '相手:' %>
186
+ <%= f.text_field :keyword, placeholder: "名前の一部でも", class: "search-input" %>
187
+ </div>
188
+
189
+ <div class="selection-field">
190
+ <%= f.label :result_id, '結果:' %>
191
+ <%= f.collection_select :result_id, Result.all, :id, :name, {} %>
192
+ </div>
193
+
194
+ <div class="selection-field">
195
+ <%= f.label :type_id, '戦型:' %>
196
+ <%= f.collection_select :type_id, Type.all, :id, :name, {} %>
197
+ </div>
198
+
199
+ <%= f.submit "????", class: "search-btn" %>
200
+
187
201
  <h2><棋譜一覧></h2>
188
202
 
189
203
  <div class="kifu-lists">
@@ -221,11 +235,16 @@
221
235
  </div>
222
236
  ```
223
237
 
238
+ app/views/kifus/search.html.erb
239
+ ```html
240
+ // indexと同じコード
241
+ ```
242
+
224
243
  # 調べた内容
225
244
  ・[【Rails】複数の条件の検索機能を作る。日付範囲検索を行う](https://qiita.com/poire_prog/items/48f569cdfc8000e18896)
226
245
  ・[【Rails】キーワード追加検索、絞り込み検索](https://qiita.com/tomaaaaaaaa/items/4c2beeb504da058408a4)
227
246
 
228
- いずれも、現在のコードどう結びくか分からないです。上記の参考で方向性は間違いないでしょうか?現在のアプリに合うような絞り込み検索の方向性についご教授いただけると幸いです。
247
+ 検索をかけても、search.html.erbに飛んで棋譜がひとつも出きません。原因をご教授いただきたいです。
229
248
 
230
249
  # バージョン情報
231
250
  ruby 2.6.5p114

2

「調べた内容」の最後の2文

2020/10/31 13:32

投稿

Zengo_Master
Zengo_Master

スコア19

title CHANGED
File without changes
body CHANGED
@@ -225,7 +225,7 @@
225
225
  ・[【Rails】複数の条件の検索機能を作る。日付範囲検索を行う](https://qiita.com/poire_prog/items/48f569cdfc8000e18896)
226
226
  ・[【Rails】キーワード追加検索、絞り込み検索](https://qiita.com/tomaaaaaaaa/items/4c2beeb504da058408a4)
227
227
 
228
- いずれも、現在のアプリの構造に合わないです。現在のアプリに合うような絞り込み検索の方向性について、ご教授いただけると幸いです。
228
+ いずれも、現在のコードとどう結びつくか分からないです。上記の参考で方向性は間違いないでしょうか?現在のアプリに合うような絞り込み検索の方向性について、ご教授いただけると幸いです。
229
229
 
230
230
  # バージョン情報
231
231
  ruby 2.6.5p114

1

バージョン情報追加

2020/10/28 23:37

投稿

Zengo_Master
Zengo_Master

スコア19

title CHANGED
File without changes
body CHANGED
@@ -225,4 +225,8 @@
225
225
  ・[【Rails】複数の条件の検索機能を作る。日付範囲検索を行う](https://qiita.com/poire_prog/items/48f569cdfc8000e18896)
226
226
  ・[【Rails】キーワード追加検索、絞り込み検索](https://qiita.com/tomaaaaaaaa/items/4c2beeb504da058408a4)
227
227
 
228
- いずれも、現在のアプリの構造に合わないです。現在のアプリに合うような絞り込み検索の方向性について、ご教授いただけると幸いです。
228
+ いずれも、現在のアプリの構造に合わないです。現在のアプリに合うような絞り込み検索の方向性について、ご教授いただけると幸いです。
229
+
230
+ # バージョン情報
231
+ ruby 2.6.5p114
232
+ Rails 6.0.3.4