Commit 4c67bd5c by Nguyen Quoc Kien

Fix: search product

parent 882dbee9
......@@ -4,7 +4,7 @@ class SearchController < ApplicationController
if params[:keyword].nil?
@products = []
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
......@@ -25,6 +25,10 @@ class Product < ActiveRecord::Base
end
end
def self.search(keyword)
Product.where("name like '%#{keyword}%'")
end
private
def ensure_not_referenced_by_any_cart_product
......
<% provide(:title, "Search Products") %>
<h2 class="text-left">Search Products with keyword: <%= params[:keyword] %></h2>
<%= will_paginate @products %>
<div class="col-md-12" style="text-align: center;">
<% if @products!= [] %>
<% @products.each do |product| %>
......@@ -27,4 +28,4 @@
<h1> Not found</h1>
<% end %>
</div>
<%= will_paginate @products %>
\ No newline at end of file
<%= will_paginate @products %>
\ No newline at end of file
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