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
Post a Comment