Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search result is not displaying

I have an issue in searching records from the PostgreSQL with particular search keyword but no record is displaying here is the code

 filter_text=params[:filter_search]
 @outputs = Output.where("name LIKE '%#{filter_text}%'").order("name ASC")
like image 278
Ahmad hayat Avatar asked Aug 02 '16 07:08

Ahmad hayat


3 Answers

Try this :

    filter_text=params[:filter_search] 
    @outputs = Output.where("name LIKE ?","%#{filter_text}%").order("name ASC")
like image 69
孙悟空 Avatar answered Sep 21 '22 17:09

孙悟空


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

@outputs = Output.search(name_cont: params[:filter_search]).result.order("name ASC")
like image 27
titan Avatar answered Sep 20 '22 17:09

titan


If you are going for case insensitive search go for ILIKE

filter_text = params[:filter_search]
@outputs = Output.where("name ILIKE ?", "'%#{filter_text}%'").order("name ASC")
like image 23
Deepak Mahakale Avatar answered Sep 20 '22 17:09

Deepak Mahakale