質問編集履歴
1
実装の流れや試したことを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
### 発生している問題・エラーメッセージ
|
5
5
|
その中でUser検索フォームを実装したいのですが、フォームの検索ボタンを押しても何も起こらなくなってしまい、エラーも表示されません。
|
6
6
|
|
7
|
+
現在実装済みの機能としては、投稿機能、フォロー・アンフォロー機能、ログイン機能等です。
|
8
|
+
下記**太線部**を検索フォームの実装にあたり変更いたしました。
|
9
|
+
|
10
|
+
お手数おかけいたしますが、何卒よろしくお願いいたします。
|
11
|
+
|
7
12
|
### 該当のソースコード
|
8
13
|
```
|
9
14
|
class User < ApplicationRecord
|
@@ -40,13 +45,13 @@
|
|
40
45
|
Post.where(user_id: self.following_ids + [self.id])
|
41
46
|
end
|
42
47
|
|
43
|
-
def self.search(search)
|
48
|
+
**def self.search(search)
|
44
49
|
if search
|
45
50
|
User.where(['name LIKE ?', "%#{search}%"])
|
46
51
|
else
|
47
52
|
User.all
|
48
53
|
end
|
49
|
-
|
54
|
+
end**
|
50
55
|
end
|
51
56
|
```
|
52
57
|
|
@@ -54,9 +59,9 @@
|
|
54
59
|
class UsersController < ApplicationController
|
55
60
|
before_action :require_user_logged_in, only: [:index, :show, :followings, :followers]
|
56
61
|
|
57
|
-
def index
|
62
|
+
**def index
|
58
63
|
@users = User.paginate(page: params[:page], per_page: 5).search(params[:search])
|
59
|
-
end
|
64
|
+
end**
|
60
65
|
|
61
66
|
def show
|
62
67
|
@user = User.find(params[:id])
|
@@ -101,10 +106,10 @@
|
|
101
106
|
```
|
102
107
|
```
|
103
108
|
#users/index
|
104
|
-
<%= form_tag(users_path, :method => "get") do %>
|
109
|
+
**<%= form_tag(users_path, :method => "get") do %>
|
105
110
|
<%= text_field_tag :search %>
|
106
111
|
<%= submit_tag "Search" ,:name => nil ,class: "button is-info"%>
|
107
|
-
<% end %>
|
112
|
+
<% end %> **
|
108
113
|
```
|
109
114
|
```
|
110
115
|
Rails.application.routes.draw do
|
@@ -132,6 +137,7 @@
|
|
132
137
|
end
|
133
138
|
```
|
134
139
|
### 試したこと
|
140
|
+
変更にあたり、モデルのカラムやルーティングを確認しましたが、誤っていないようです。
|
141
|
+
よろしくお願いいたします。
|
135
142
|
|
136
|
-
|
137
143
|
### 補足情報(FW/ツールのバージョンなど)
|