質問編集履歴
3
本文の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,6 +44,90 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
+
-------------------------------------------------------
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
search.rb
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
class Search < ApplicationRecord
|
56
|
+
|
57
|
+
def self.search(search) #self.でクラスメソッドとしている
|
58
|
+
|
59
|
+
if search # Controllerから渡されたパラメータが!= nilの場合は、titleカラムを部分一致検索
|
60
|
+
|
61
|
+
Search.where(['name LIKE ?', "%#{search}%"])
|
62
|
+
|
63
|
+
else
|
64
|
+
|
65
|
+
Search.all #全て表示。
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
---------------------------------------------------------
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
index.html.erb
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
<%= form_tag searchs_path, :method => 'get' do %>
|
84
|
+
|
85
|
+
<p>
|
86
|
+
|
87
|
+
<%= text_field_tag :search, params[:search] %>
|
88
|
+
|
89
|
+
<%= submit_tag "Search", :name => nil %>
|
90
|
+
|
91
|
+
</p>
|
92
|
+
|
93
|
+
<% end %>
|
94
|
+
|
95
|
+
<%= yield %>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
---------------------------------------------------------
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
routes.rb
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
resources:searchs
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
-----------------------------------------------------------------
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
searchscontroller.rb
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
class SearchsController < ApplicationController
|
120
|
+
|
121
|
+
def index
|
122
|
+
|
123
|
+
@projects = Search.search(params[:search])
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
47
131
|
![イメージ説明](90d5ab58a9c139090423dbc35290382e.png)
|
48
132
|
|
49
133
|
![イメージ説明](d7c29e0c54acfbfcb4440ffafe16269c.png)
|
2
書き方変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Ruby on Railsで検索機能を実装したい
|
1
|
+
Ruby on Railsで検索機能を実装したらtext/htmlがない、というエラーが出る
|
test
CHANGED
File without changes
|
1
書式の改善
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Ruby on Railsで検索機能
|
1
|
+
Ruby on Railsで検索機能を実装したい
|
test
CHANGED
File without changes
|