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")
Try this :
filter_text=params[:filter_search]
@outputs = Output.where("name LIKE ?","%#{filter_text}%").order("name ASC")
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")
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With