Search result not displayed

I have a problem finding posts from PostgreSQL with a specific search keyword, but there is no entry here, this is the code

filter_text=params[:filter_search] @outputs = Output.where("name LIKE '%#{filter_text}%'").order("name ASC") 
+5
source share
5 answers

If you use ransack gem, this will allow you to use simple methods for search . Using ransack , you only need to do this:

 @outputs = Output.search(name_cont: params[:filter_search]).result.order("name ASC") 
+3
source

Try the following:

  filter_text=params[:filter_search] @outputs = Output.where("name LIKE ?","%#{filter_text}%").order("name ASC") 
+7
source

If you are looking for a case insensitive case, go to ILIKE

 filter_text = params[:filter_search] @outputs = Output.where("name ILIKE ?", "'%#{filter_text}%'").order("name ASC") 
+3
source

Instead:

 filter_text=params[:filter_search] @outputs = Output.where("name LIKE '%#{filter_text}%'").order("name ASC") 

Try the following:

 filter_text=params[:filter_search] @outputs = Output.where(["name LIKE ?", "%#{filter_text}%"]).order("name ASC") 
+3
source

One easy way to search is to use Ransack . This provides an efficient search engine.

+1
source

All Articles