###前提・実現したいこと
検索フォームのテストをしておりまして、home#indexページに検索フォームを実装しています。
ただ、今回別のページにも検索フォームを実装したいのですが、なかなかうまくいかずにいます。
内容は、home#indexで実装できている検索フォームでサイト内の検索ができるようにしています。(ログイン・未ログイン問わず閲覧可能)
そしてそれとは別に、ログインしているユーザーがいて、そのユーザーが投稿した内容のみを検索にかけたいのですが、ログインユーザーページの検索フォームで検索したらhome#indexで検索をかけた時と同じ全ログインユーザーの投稿が検索結果として表示されてしまいます。
###home/index.html.erb
<div class = "search_bar"> <%= search_form_for @q, url: buildings_path do |f| %> <%= f.submit :class => "searchbtn" %> </div> <% end %>###controllers/home_controller.rb(トップページ)
class HomeController < ApplicationController
def index
@q = Building.search(params[:q])
@buildings = @q.result(distinct: true)
end
end
###show.html.erb(ログインユーザー用投稿一覧ページ)
<div class = "search_bar"> <%= search_form_for @q, url: buildings_path do |f| %> <%= f.submit :class => "searchbtn" %> </div> <% end %>###class BuildingsController < ApplicationController
def show
@q = Building.search(params[:q])
@buildings = @q.result(distinct: true)
end
###補足
トップページとログインユーザー用登録ページのフォームのコードを同じにしているのが問題なのでしょうか。
初心者ですがどうどよろしくお願いします
あなたの回答
tips
プレビュー