Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venshop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Nguyen Quoc Kien
venshop
Commits
c9b28616
Commit
c9b28616
authored
Aug 11, 2015
by
Nguyen Quoc Kien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix search with key word=nil
parent
62b701c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
app/controllers/search_controller.rb
+7
-2
app/views/search/search.html.erb
+1
-1
No files found.
app/controllers/search_controller.rb
View file @
c9b28616
...
...
@@ -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
app/views/search/search.html.erb
View file @
c9b28616
<%
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
!=
[]
%>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment