Commit 841bca67 by vulehuan

display error messages in some case raise exception

parent e9292941
...@@ -469,3 +469,7 @@ footer { ...@@ -469,3 +469,7 @@ footer {
.block-search-result { .block-search-result {
padding-top: 10px; padding-top: 10px;
} }
#block-message-visible {
margin-top: 10px;
}
...@@ -51,12 +51,14 @@ class CardsController < ApplicationController ...@@ -51,12 +51,14 @@ class CardsController < ApplicationController
# if add a product to card # if add a product to card
# first time add to card # first time add to card
if @card_infos.empty? if @card_infos.empty?
if Product.exists?(params[:product_id])
product = Product.find(params[:product_id]) product = Product.find(params[:product_id])
card_items = Array.new card_items = Array.new
card_items.push({ product_id: params[:product_id], quantity: 1 }) card_items.push({ product_id: params[:product_id], quantity: 1 })
customer_info = Hash.new customer_info = Hash.new
@card_infos = { card_items: card_items, customer_info: customer_info } @card_infos = { card_items: card_items, customer_info: customer_info }
session[:SHOPPING_CARD_SESSION_NAME] = @card_infos session[:SHOPPING_CARD_SESSION_NAME] = @card_infos
end
redirect_to cards_path redirect_to cards_path
else else
card_items = @card_infos[:card_items] card_items = @card_infos[:card_items]
......
...@@ -2,14 +2,14 @@ class ProductCategoriesController < ApplicationController ...@@ -2,14 +2,14 @@ class ProductCategoriesController < ApplicationController
add_breadcrumb "Products", :products_path add_breadcrumb "Products", :products_path
def show def show
if ProductCategory.exists?(params[:id])
term = ProductCategory.find(params[:id]) term = ProductCategory.find(params[:id])
if term.nil?
@items = Array.new
@title = ''
else
@items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 24) @items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 24)
@title = term.name @title = term.name
add_breadcrumb term.name, product_category_path(term) add_breadcrumb term.name, product_category_path(term)
else
flash[:error] = "Invalid product category!"
redirect_to products_path
end end
end end
end end
...@@ -7,6 +7,7 @@ class ProductsController < ApplicationController ...@@ -7,6 +7,7 @@ class ProductsController < ApplicationController
end end
def show def show
begin
@product = Product.find(params[:id]) @product = Product.find(params[:id])
if !@product.status if !@product.status
user = current_user user = current_user
...@@ -20,6 +21,10 @@ class ProductsController < ApplicationController ...@@ -20,6 +21,10 @@ class ProductsController < ApplicationController
add_breadcrumb @product.name, product_path(@product) add_breadcrumb @product.name, product_path(@product)
end end
@other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 20) @other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 20)
rescue
flash[:error] = "Invalid product!"
redirect_to products_path
end
end end
def new def new
......
...@@ -13,7 +13,12 @@ class UsersController < ApplicationController ...@@ -13,7 +13,12 @@ class UsersController < ApplicationController
end end
def show def show
if User.exists?(params[:id])
@user = User.find(params[:id]) @user = User.find(params[:id])
else
flash[:error] = "Invalid user!"
redirect_to root_path
end
end end
def create def create
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<h2 class="sprite-2"> <h2 class="sprite-2">
Recommended Items<span class="sprite-2"></span> Recommended Items<span class="sprite-2"></span>
</h2> </h2>
<div id="block-message-visible" class="hidden"></div>
<%= render 'shared/grid', items: @recommed_items %> <%= render 'shared/grid', items: @recommed_items %>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<h2 class="sprite-2"> <h2 class="sprite-2">
Products<span class="sprite-2"></span> Products<span class="sprite-2"></span>
</h2> </h2>
<div id="block-message-visible" class="hidden"></div>
<%= render 'shared/grid', items: @products %> <%= render 'shared/grid', items: @products %>
<%= will_paginate @products, renderer: BootstrapPagination::Rails %> <%= will_paginate @products, renderer: BootstrapPagination::Rails %>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<div class="body-box"> <div class="body-box">
<h2 class="sprite-2"><%= @product.name %><span class="sprite-2"></span></h2> <h2 class="sprite-2"><%= @product.name %><span class="sprite-2"></span></h2>
<div class="text-justify product-detail"> <div class="text-justify product-detail">
<div id="block-message-visible" class="hidden"></div>
<% if !@product.status %> <% if !@product.status %>
<div class="alert alert-danger"> <div class="alert alert-danger">
<p class="text-center">This product is only visible to you.</p> <p class="text-center">This product is only visible to you.</p>
......
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