Commit e9292941 by vulehuan

use .nil? instead of == or != symbol

parent 7a96ae3e
...@@ -3,12 +3,12 @@ class CardsController < ApplicationController ...@@ -3,12 +3,12 @@ class CardsController < ApplicationController
def index def index
@card_infos = Hash.new @card_infos = Hash.new
if session[:SHOPPING_CARD_SESSION_NAME] != nil if !session[:SHOPPING_CARD_SESSION_NAME].nil?
Please register or sign in to reply
@card_infos = session[:SHOPPING_CARD_SESSION_NAME] @card_infos = session[:SHOPPING_CARD_SESSION_NAME]
end end
if params[:product_id] != nil if !params[:product_id].nil?
# if remove a product from card # if remove a product from card
if params[:card_action] != nil && params[:card_action] == 'remove' if !params[:card_action].nil? && params[:card_action] == 'remove'
# Nothing to delete # Nothing to delete
if @card_infos.empty? if @card_infos.empty?
redirect_to cards_path redirect_to cards_path
...@@ -24,14 +24,14 @@ class CardsController < ApplicationController ...@@ -24,14 +24,14 @@ class CardsController < ApplicationController
end end
end end
end end
elsif params[:card_action] != nil && params[:card_action] == 'update' elsif !params[:card_action].nil? && params[:card_action] == 'update'
# Nothing to update # Nothing to update
if @card_infos.empty? if @card_infos.empty?
redirect_to cards_path redirect_to cards_path
else else
quantity = params[:quantity] quantity = params[:quantity]
# Invalid request # Invalid request
if quantity == nil || quantity.to_i <= 0 if quantity.nil? || quantity.to_i <= 0
redirect_to cards_path redirect_to cards_path
else else
card_items = @card_infos[:card_items] card_items = @card_infos[:card_items]
...@@ -84,7 +84,7 @@ class CardsController < ApplicationController ...@@ -84,7 +84,7 @@ class CardsController < ApplicationController
def checkout def checkout
add_breadcrumb "Checkout", url_for(action: 'checkout') add_breadcrumb "Checkout", url_for(action: 'checkout')
@card_infos = Hash.new @card_infos = Hash.new
if session[:SHOPPING_CARD_SESSION_NAME] != nil if !session[:SHOPPING_CARD_SESSION_NAME].nil?
@card_infos = session[:SHOPPING_CARD_SESSION_NAME] @card_infos = session[:SHOPPING_CARD_SESSION_NAME]
end end
if @card_infos.empty? if @card_infos.empty?
...@@ -133,7 +133,7 @@ class CardsController < ApplicationController ...@@ -133,7 +133,7 @@ class CardsController < ApplicationController
add_breadcrumb "Check out", url_for(action: 'checkout') add_breadcrumb "Check out", url_for(action: 'checkout')
add_breadcrumb "Confirm", url_for(action: 'confirm_checkout') add_breadcrumb "Confirm", url_for(action: 'confirm_checkout')
@card_infos = Hash.new @card_infos = Hash.new
if session[:SHOPPING_CARD_SESSION_NAME] != nil if !session[:SHOPPING_CARD_SESSION_NAME].nil?
@card_infos = session[:SHOPPING_CARD_SESSION_NAME] @card_infos = session[:SHOPPING_CARD_SESSION_NAME]
end end
if @card_infos.empty? if @card_infos.empty?
......
...@@ -3,7 +3,7 @@ class ProductCategoriesController < ApplicationController ...@@ -3,7 +3,7 @@ class ProductCategoriesController < ApplicationController
def show def show
term = ProductCategory.find(params[:id]) term = ProductCategory.find(params[:id])
if term == nil if term.nil?
@items = Array.new @items = Array.new
@title = '' @title = ''
else else
......
class ProductsController < ApplicationController class ProductsController < ApplicationController
add_breadcrumb "Products", :products_path add_breadcrumb "Products", :products_path
before_action :signed_in_user, only: [:new] before_action :signed_in_user, only: [:new]
def index def index
@products = Product.get_list(limit: 24, page: params[:page]) @products = Product.get_list(limit: 24, page: params[:page])
end end
def show def show
@product = Product.find(params[:id]) @product = Product.find(params[:id])
if !@product.status if !@product.status
user = current_user user = current_user
if user == nil || @product.user_id != user.id if user.nil? || @product.user_id != user.id
redirect_to products_path redirect_to products_path
end end
end end
product_category = ProductCategory.find(@product.product_category_id) product_category = ProductCategory.find(@product.product_category_id)
if product_category != nil if !product_category.nil?
add_breadcrumb product_category.name, product_category_path(product_category) add_breadcrumb product_category.name, product_category_path(product_category)
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)
end end
def new def new
...@@ -44,13 +44,13 @@ class ProductsController < ApplicationController ...@@ -44,13 +44,13 @@ class ProductsController < ApplicationController
def user_items def user_items
add_breadcrumb "My items", url_for(action: 'user_items') add_breadcrumb "My items", url_for(action: 'user_items')
user = current_user user = current_user
all_status = user != nil && user.id.to_s == params[:user_id].to_s all_status = !user.nil? && user.id.to_s == params[:user_id].to_s
@products = Product.get_user_items(limit: 16, page: params[:page], user_id: params[:user_id], all_status: all_status) @products = Product.get_user_items(limit: 16, page: params[:page], user_id: params[:user_id], all_status: all_status)
end end
def search def search
add_breadcrumb "Search results", url_for(action: 'search') add_breadcrumb "Search results", url_for(action: 'search')
if params[:keyword] == nil if params[:keyword].nil?
redirect_to products_path redirect_to products_path
end end
search = Product.search do search = Product.search do
......
<nav class="breadcrumb"> <nav class="breadcrumb">
<span>You are in: </span> <span>You are in: </span>
<ul> <ul>
<% <%
if breadcrumbs == nil || breadcrumbs.empty? if breadcrumbs.nil? || breadcrumbs.empty?
breadcrumbs = Array.new breadcrumbs = Array.new
breadcrumbs.push({ text: 'Home', url: root_path }) breadcrumbs.push({ text: 'Home', url: root_path })
else else
...@@ -18,4 +18,4 @@ ...@@ -18,4 +18,4 @@
end end
%> %>
</ul> </ul>
</nav> </nav>
\ No newline at end of file
<% <%
if items == nil || items.empty? if items.nil? || items.empty?
if params[:action] != 'search' if params[:action] != 'search'
%> %>
<p>No products available.</p> <p>No products available.</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