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
4c67bd5c
Commit
4c67bd5c
authored
Jul 31, 2015
by
Nguyen Quoc Kien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: search product
parent
882dbee9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
3 deletions
+8
-3
app/controllers/search_controller.rb
+1
-1
app/models/product.rb
+4
-0
app/views/search/search.html.erb
+3
-2
No files found.
app/controllers/search_controller.rb
View file @
4c67bd5c
...
@@ -4,7 +4,7 @@ class SearchController < ApplicationController
...
@@ -4,7 +4,7 @@ class SearchController < ApplicationController
if
params
[
:keyword
].
nil?
if
params
[
:keyword
].
nil?
@products
=
[]
@products
=
[]
else
else
@products
=
Product
.
where
(
"name like '%
#{
params
[
:keyword
]
}
%'"
).
paginate
(
page:
params
[
:page
]).
per_page
(
18
)
@products
=
Product
.
search
(
params
[
:keyword
]
).
paginate
(
page:
params
[
:page
]).
per_page
(
18
)
end
end
end
end
end
end
app/models/product.rb
View file @
4c67bd5c
...
@@ -25,6 +25,10 @@ class Product < ActiveRecord::Base
...
@@ -25,6 +25,10 @@ class Product < ActiveRecord::Base
end
end
end
end
def
self
.
search
(
keyword
)
Product
.
where
(
"name like '%
#{
keyword
}
%'"
)
end
private
private
def
ensure_not_referenced_by_any_cart_product
def
ensure_not_referenced_by_any_cart_product
...
...
app/views/search/search.html.erb
View file @
4c67bd5c
<%
provide
(
:title
,
"Search Products"
)
%>
<%
provide
(
:title
,
"Search Products"
)
%>
<h2
class=
"text-left"
>
Search Products with keyword:
<%=
params
[
:keyword
]
%>
</h2>
<h2
class=
"text-left"
>
Search Products with keyword:
<%=
params
[
:keyword
]
%>
</h2>
<%=
will_paginate
@products
%>
<div
class=
"col-md-12"
style=
"text-align: center;"
>
<div
class=
"col-md-12"
style=
"text-align: center;"
>
<%
if
@products
!=
[]
%>
<%
if
@products
!=
[]
%>
<%
@products
.
each
do
|
product
|
%>
<%
@products
.
each
do
|
product
|
%>
...
@@ -27,4 +28,4 @@
...
@@ -27,4 +28,4 @@
<h1>
Not found
</h1>
<h1>
Not found
</h1>
<%
end
%>
<%
end
%>
</div>
</div>
<%=
will_paginate
@products
%>
<%=
will_paginate
@products
%>
\ No newline at end of file
\ No newline at end of file
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