ruby - Rails - Active Record Search ".where" With Or Statement For Same Criteria -


in rails app, i'm trying let user search products using key word or key phrase matches products' descriptions , names.

according documentation, have written so:

def productsearch   @results = 0   if !params[:searchinput].nil?     @results = 1     @searchinput = params[:searchinput]     @searchcriteria = "%#{params[:searchinput]}%"     @productlist = product.where("description ? or name ?", @searchcriteria, @searchcriteria)   end end 

what frustrates me line:

@productlist = product.where("description ? or name ?", @searchcriteria, @searchcriteria) 

is there short-hand matching both description , name of product same search criteria?

i'd mention i'm new ruby on rails , school project have build e-commerce website group, appreciated.

try:

@productlist = product.where("description :search or name :search", search: @searchcriteria)


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -