Reputation: 99
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")
Upvotes: 5
Views: 577
Reputation: 676
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")
Upvotes: 3
Reputation: 1285
Try this :
filter_text=params[:filter_search]
@outputs = Output.where("name LIKE ?","%#{filter_text}%").order("name ASC")
Upvotes: 7
Reputation: 1101
One easy way to search is to use Ransack. Which provides you an efficient search mechanism.
Upvotes: 1
Reputation: 1409
Instead of:
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")
Upvotes: 3
Reputation: 23711
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")
Upvotes: 3