Commit 841bca67 by vulehuan

display error messages in some case raise exception

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