Commit a7655c6e by Vy Quoc Vu

make it better

parent 21c7c2b8
......@@ -5,7 +5,6 @@ gem 'bootstrap-sass', '3.2.0.0'
gem 'will_paginate-bootstrap'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'faker', '1.4.2'
gem 'pg'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
......
......@@ -80,7 +80,6 @@ GEM
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pg (0.17.1)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
......@@ -232,7 +231,6 @@ DEPENDENCIES
mini_backtrace (= 0.1.3)
minitest-reporters (= 1.0.5)
mysql2
pg (= 0.17.1)
rails (= 4.2.3)
rails_12factor (= 0.0.2)
sass-rails (~> 5.0)
......
class Admins::ProductsController < ApplicationController
def new
@product = Product.new
end
def create
if admin_signed_in?
if product_params[:price].to_i >= 0 && params[:category][:id].to_i > 0 && !product_params[:image].nil? && !product_params[:image].empty? && !product_params[:price].empty? && !product_params[:name].empty? && product_params[:price].to_i <= 999999
if product_params[:price].to_i >= 0 && params[:category][:id].to_i > 0 &&
!product_params[:image].nil? && !product_params[:image].empty? &&
!product_params[:price].empty? && !product_params[:name].empty? &&
product_params[:price].to_i <= 999999
product = Product.find_or_create_by(name: product_params[:name]) do |product|
product.image = product_params[:image]
product.category_id = params[:category][:id]
......@@ -24,8 +27,10 @@ class Admins::ProductsController < ApplicationController
def edit
if admin_signed_in?
if product_params[:price].to_i >= 0 && params[:category][:id].to_i > 0 && !product_params[:image].nil? && !product_params[:image].empty? && !product_params[:price].empty? && !product_params[:name].empty? && product_params[:price].to_i <= 999999
if product_params[:price].to_i >= 0 && params[:category][:id].to_i > 0 &&
!product_params[:image].nil? && !product_params[:image].empty? &&
!product_params[:price].empty? && !product_params[:name].empty? &&
product_params[:price].to_i <= 999999
product = Product.find(params[:id])
product.name = product_params[:name]
product.image = product_params[:image]
......
class Admins::UsersController < ApplicationController
def index
if admin_signed_in?
@users = User.all
end
end
end
......@@ -9,7 +9,6 @@ class ApplicationController < ActionController::Base
include CategoriesHelper
include SessionsHelper
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :username
end
......
......@@ -12,8 +12,8 @@ class CartProductsController < ApplicationController
if session[:cart] then
cart_product = session[:cart]
else
session[:cart] ={}
cart_product = session[:cart]
session[:cart] ={}
cart_product = session[:cart]
end
if cart_product[id] then
......@@ -21,8 +21,8 @@ class CartProductsController < ApplicationController
else
cart_product[id] = params[:quantity].to_i
end
flash[:success] = "success"
redirect_to :back
flash[:success] = "success"
redirect_to :back
end
end
......@@ -39,6 +39,7 @@ class CartProductsController < ApplicationController
end
redirect_to :action => :index
end
def clear
session[:cart] = nil
redirect_to :action => :index
......@@ -51,4 +52,5 @@ class CartProductsController < ApplicationController
@cart_product = {}
end
end
end
\ No newline at end of file
class CartsController < ApplicationController
include CategoriesHelper
def show
if user_signed_in?
@show_cart = Cart.where(user_id: current_user.id)
......
......@@ -3,7 +3,7 @@ class Emailer < ApplicationMailer
include CartsHelper
include CategoriesHelper
def send_email_to(email,cart)
mail to: email, subject: "Venshop!!"
@cart_product = cart
mail to: email, subject: "Venshop!!"
end
end
<h1>Your Cart</h1>
<ul>
<% total = 0 %>
<% if !@cart_product.nil? %>
<% @cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% total = total + product.price * quantity %>
<li>
<%= link_to truncate(product.name, length:15), "/products/#{product.id}" %>
<%= quantity %>
</li>
<% total = total + product.price * quantity.to_i %>
<div class="col-md-4">
<%= image_tag(product.image, size: "170x210")%>
<h5><%= truncate(product.name, length: 22) %></h5>
<%= number_to_currency(product.price/100.to_f) %>
</br>
</div>
<% end %>
<% end -%>
<% else %>
<h3>Empty</h3>
<h2> Total price: <%=(total/100.to_f).to_s + "$" %></h2>
<% end -%>
<br>
<br>
<h2> <%= number_to_currency(total/100.to_f, :unit => '$')%> </h2>
<h2> Thank !</h2>
</ul>
</ul>
\ 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