質問編集履歴
1
コードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
3行目のfが定義されていないとのことですが、1行目の|f|で定義されていることにはならないのでしょうか。
|
8
8
|
|
9
|
-
|
9
|
+
### index.html.slim
|
10
10
|
```
|
11
11
|
h1
|
12
12
|
| 学生検索
|
@@ -25,11 +25,39 @@
|
|
25
25
|
td
|
26
26
|
= student.subjects.map{|subject_id| Subject.find(subject_id).name}.join(', ')
|
27
27
|
```
|
28
|
-
|
28
|
+
### _search_form.html.slim
|
29
29
|
```
|
30
30
|
= search_form_for(@q, url:search_path) do |f|
|
31
31
|
/検索フォームをここに書く
|
32
32
|
= f.submit
|
33
33
|
```
|
34
34
|
|
35
|
+
### students_controller
|
36
|
+
```
|
37
|
+
class StudentsController < ApplicationController
|
38
|
+
def index
|
39
|
+
@q = Student.ransack(params[:q])
|
40
|
+
@students = @q.result(distinct: true)
|
41
|
+
end
|
42
|
+
|
43
|
+
def search
|
44
|
+
@q = Student.search(search_params)
|
45
|
+
@students = @q.result(distinct: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def search_params
|
50
|
+
params.require(:q).permit!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
### routes.rb
|
56
|
+
```
|
57
|
+
Rails.application.routes.draw do
|
58
|
+
root to: 'students#index'
|
59
|
+
get 'search', to: 'students#search'
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
35
63
|
まだ初学者の域を出ないため、とんちんかんなことを言ってるかもしれませんが、どなたか原因が分かる方に教えていただけるとありがたいです。
|