Commit 26aab3c8 by Tran Hoang Viet

VietTH: Fix review code feature search

parent 5a3bd5d8
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
layout Proc.new { |controller| controller.devise_controller? ? 'devise' : 'application' } layout Proc.new { |controller| controller.devise_controller? ? 'devise' : 'application' }
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
...@@ -14,4 +15,8 @@ class ApplicationController < ActionController::Base ...@@ -14,4 +15,8 @@ class ApplicationController < ActionController::Base
def add_breadcrumb_home def add_breadcrumb_home
add_breadcrumb('Home', root_path) add_breadcrumb('Home', root_path)
end end
def record_not_found
redirect_to(root_path, alert: "Resource not found")
end
end end
\ No newline at end of file
...@@ -7,8 +7,7 @@ class CategoriesController < ApplicationController ...@@ -7,8 +7,7 @@ class CategoriesController < ApplicationController
private private
def set_category def set_category
@category = Category.find_by(id: params[:id]) @category = Category.find(params[:id])
redirect_to root_path, alert: "Category not found" if @category.blank?
end end
end end
\ No newline at end of file
...@@ -10,7 +10,7 @@ class OrdersController < ApplicationController ...@@ -10,7 +10,7 @@ class OrdersController < ApplicationController
def create def create
if order_service.create(order_params) if order_service.create(order_params)
clear_cart clear_cart
redirect_to root_path redirect_to(root_path, notice: 'Checkout is successful.')
else else
render :index render :index
end end
......
...@@ -14,9 +14,9 @@ class ProductsController < ApplicationController ...@@ -14,9 +14,9 @@ class ProductsController < ApplicationController
def create def create
@product = Product.new(product_params) @product = Product.new(product_params)
if @product.save if @product.save
redirect_to root_path redirect_to(root_path)
else else
render :new render(:new)
end end
end end
...@@ -26,8 +26,8 @@ class ProductsController < ApplicationController ...@@ -26,8 +26,8 @@ class ProductsController < ApplicationController
end end
def add_cart def add_cart
add_to_cart @product add_to_cart(@product)
redirect_to @product redirect_to(@product, notice: 'Product is added to cart.')
end end
def search def search
...@@ -37,8 +37,7 @@ class ProductsController < ApplicationController ...@@ -37,8 +37,7 @@ class ProductsController < ApplicationController
private private
def set_product def set_product
@product = Product.find_by(id: params[:id]) @product = Product.find(params[:id])
redirect_to root_path, alert: "Product not found" if @product.blank?
end end
def set_categories def set_categories
......
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