Commit c9b28616 by Nguyen Quoc Kien

Fix search with key word=nil

parent 62b701c1
......@@ -37,8 +37,13 @@ class SearchController < ApplicationController
end
def escape_characters_in_string(keyword)
pattern = /(\+|\-|\&|\||\!|\(|\)|\{|\}|\[|\]|\^|\"|\~|\*|\?|\:|\\)/
return keyword.gsub(pattern){|match|"\\" + match}
if keyword == ""
flash[:danger] = "Keyword is null"
redirect_to products_path
else
pattern = /(\+|\-|\&|\||\!|\(|\)|\{|\}|\[|\]|\^|\"|\~|\*|\?|\:|\ |\\)/
return keyword.gsub(pattern){|match|"\\" + match}
end
end
end
<% provide(:title, "Search Products") %>
<h2 class="text-left">Search Products with keyword: <%= params[:keyword] %> - <%= @products.count %> resulfs</h2>
<h2 class="text-left">Search Products with keyword: "<%= params[:keyword] %>" - <%= @products.count %> resulfs</h2>
<div class="col-md-12" style="text-align: center;">
<% if @products!= [] %>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment