Posts

Showing posts with the label pg-search

Finding posts under a category name keyword with pg_search on Rails 5

Finding posts under a category name keyword with pg_search on Rails 5 I'm using gem pg_search and doing multi-search for Website and Post tables. I am able to search by records title, but I also want to be able to search records based on categories they belong to. pg_search So, for example, when I type "typographic" (category name) to search input, all Website and Post records under that category should be listed, as well as all records that have "Typographic" in the title. I think it can be done with association but I could not make it work 🤷‍♂️ _header.html.erb <%= form_tag search_index_path, method: :get do %> <%= text_field_tag :query, params[:query], placeholder: "Search" %> <% end %> search_controller.rb class SearchController < ApplicationController def index @pg_search_result = PgSearch.multisearch(params[:query]) end end models/post.rb class Post < ApplicationRecord include PgSearch multisearchable :ag...