Ahmad hayat Ahmad hayat - 4 months ago 9
Ruby Question

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")

Answer

If you use ransack gem, it will allow you 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")

Hope it solves your problem.

Comments