Commit a7655c6e by Vy Quoc Vu

make it better

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