Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
891db03
gem bootstrap
Falcon-7X Feb 3, 2017
8a55e4b
bootstrap to html and bootstrap flash
Falcon-7X Feb 3, 2017
3901cb5
gem simple_form
Falcon-7X Feb 4, 2017
4c4263d
install gem devise
Falcon-7X Feb 4, 2017
aeb9bc7
add login/regist
Falcon-7X Feb 4, 2017
60cf07e
admin/index and show
Falcon-7X Feb 4, 2017
bc18ee8
CRUD except Destroy
Falcon-7X Feb 5, 2017
addb67f
Destroy of CRUD
Falcon-7X Feb 5, 2017
90df720
authenticate_user can do CRUD
Falcon-7X Feb 5, 2017
5a2c34b
edit and destroy botton of index views
Falcon-7X Feb 5, 2017
0b2c1e8
correct the botton of edit and destroy onthe index views
Falcon-7X Feb 5, 2017
0a4f91d
add require_is_admin without push email to database
Falcon-7X Feb 6, 2017
e249e69
push admin email to db
Falcon-7X Feb 6, 2017
8f59a5d
implement image upload
Falcon-7X Feb 6, 2017
b1c4374
implement user product show
Falcon-7X Feb 6, 2017
d25ce07
replace back platform index
Falcon-7X Feb 6, 2017
9149ac8
gem splite3 for heroku
Falcon-7X Feb 6, 2017
bc55106
add add_to_cart button
Falcon-7X Feb 7, 2017
ecf875f
implement add_product_to_cart FUNC.
Falcon-7X Feb 7, 2017
509c4a6
implement current_cart FUNC.
Falcon-7X Feb 7, 2017
d0d5770
implement cart index
Falcon-7X Feb 7, 2017
1408a36
optimize cart_total_price
Falcon-7X Feb 7, 2017
e5a7b3d
implement delete one cart_item FUNC.
Falcon-7X Feb 7, 2017
23450c6
clean cart FUNC.
Falcon-7X Feb 7, 2017
bfc81bd
add_to_cart only one time
Falcon-7X Feb 8, 2017
f2e8311
add cart_item quantity in cart
Falcon-7X Feb 8, 2017
e6e1bf5
add can not buy 0 quantity product
Falcon-7X Feb 8, 2017
aa88187
add quantity of cart_item equal the prodcut quantity
Falcon-7X Feb 8, 2017
540fa32
add checkout routing
Falcon-7X Feb 8, 2017
137443b
add order model
Falcon-7X Feb 8, 2017
0c59973
checkout page views
Falcon-7X Feb 8, 2017
dc93813
order controller
Falcon-7X Feb 8, 2017
52383c4
add product_list model
Falcon-7X Feb 8, 2017
5695408
order show
Falcon-7X Feb 8, 2017
8b7277c
add_token_to_order
Falcon-7X Feb 8, 2017
c293d7d
my orders in nav
Falcon-7X Feb 9, 2017
9a37e94
my order DESC
Falcon-7X Feb 9, 2017
cc7e551
my order DESC R01
Falcon-7X Feb 9, 2017
83a4f78
add commit
Falcon-7X Feb 13, 2017
03035c7
add admin seed
Falcon-7X Feb 14, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
# Ignore Byebug command history file.
.byebug_history
config/database.yml
public/uploads
19 changes: 15 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
Expand All @@ -29,20 +29,31 @@ gem 'jbuilder', '~> 2.5'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'bootstrap-sass'
gem 'simple_form'
gem 'devise'
gem 'carrierwave'
gem 'mini_magick'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'sqlite3'
#for heroku
end

group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
# gem 'spring'
# gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :production do
gem 'pg'
end
# for heroku
40 changes: 33 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (7.1.1)
autoprefixer-rails (6.6.1)
execjs
bcrypt (3.1.11)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (9.0.5)
carrierwave (1.0.0)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.2.x)
Expand All @@ -50,6 +60,12 @@ GEM
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
debug_inspector (0.0.2)
devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.1)
responders
warden (~> 1.2.3)
erubis (2.7.0)
execjs (2.7.0)
ffi (1.9.14)
Expand All @@ -74,13 +90,16 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_magick (4.6.0)
mini_portile2 (2.1.0)
minitest (5.9.0)
multi_json (1.12.1)
nio4r (1.2.1)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
orm_adapter (0.5.0)
pg (0.19.0)
pkg-config (1.1.7)
puma (3.6.0)
rack (2.0.1)
Expand Down Expand Up @@ -113,17 +132,18 @@ GEM
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
spring (1.7.2)
spring-watcher-listen (2.0.0)
listen (>= 2.7, < 4.0)
spring (~> 1.2)
simple_form (3.3.1)
actionpack (> 4, < 5.1)
activemodel (> 4, < 5.1)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -142,6 +162,8 @@ GEM
thread_safe (~> 0.1)
uglifier (3.0.1)
execjs (>= 0.3.0, < 3)
warden (1.2.6)
rack (>= 1.0)
web-console (3.3.1)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -155,21 +177,25 @@ PLATFORMS
ruby

DEPENDENCIES
bootstrap-sass
byebug
carrierwave
coffee-rails (~> 4.2)
devise
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
mini_magick
pg
puma (~> 3.0)
rails (~> 5.0.0)
sass-rails (~> 5.0)
spring
spring-watcher-listen (~> 2.0.0)
simple_form
sqlite3
turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
web-console

BUNDLED WITH
1.12.5
1.13.6
3 changes: 3 additions & 0 deletions app/assets/javascripts/account/orders.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/products.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require bootstrap/alert
//= require bootstrap/dropdown
3 changes: 3 additions & 0 deletions app/assets/javascripts/cart_items.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/carts.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/orders.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/products.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/welcome.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/account/orders.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the account/orders controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/products.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin/products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
*= require_tree .
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";
3 changes: 3 additions & 0 deletions app/assets/stylesheets/cart_items.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the cart_items controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/carts.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the carts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/orders.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the orders controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/products.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/welcome.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the welcome controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
6 changes: 6 additions & 0 deletions app/controllers/account/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Account::OrdersController < ApplicationController
before_action :authenticate_user!
def index
@orders = current_user.orders.order("id DESC")
end
end
58 changes: 58 additions & 0 deletions app/controllers/admin/products_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class Admin::ProductsController < ApplicationController
before_action :authenticate_user! , only: [:new, :create, :edit, :update, :destroy]
# before_action must login!
before_filter :require_is_admin
# only admin can into back platform!
def index
@products = Product.all
end

def show
@product = Product.find(params[:id])
end

def new
@product = Product.new
end

def create
@product = Product.new(product_params)

if @product.save
redirect_to admin_products_path
else
render :new
end
end

def edit
@product = Product.find(params[:id])
end

def update
@product = Product.find(params[:id])

if @product.update(product_params)
redirect_to admin_products_path, notice: "产品更新成功!"
else
render :edit
end
end

def destroy
@product = Product.find(params[:id])

@product.destroy
redirect_to admin_products_path, alert: '产品删除成功!'
end




private

def product_params
params.require(:product).permit(:title, :description, :quantity, :price, :image)

end
end
26 changes: 26 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

def require_is_admin
if !current_user.admin?
flash[:alert] = 'You are not admin!'
redirect_to root_path
end
end

helper_method :current_cart
# current_cart其实原本是一个 controller 内的 method,我们为了要在 view 里面要可以存取它。
# 所以,我们得在 applications_controller.rb 宣告他是 helper_method,才能直接存取。
def current_cart
@current_cart ||= find_cart
end

private

def find_cart
cart = Cart.find_by(id: session[:cart_id])
if cart.blank?
cart = Cart.create
end
session[:cart_id] = cart.id
return cart
end

end
34 changes: 34 additions & 0 deletions app/controllers/cart_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class CartItemsController < ApplicationController
before_action :authenticate_user!

def destroy
@cart = current_cart
@cart_item = @cart.cart_items.find_by(product_id: params[:id])
@product = @cart_item.product
@cart_item.destroy

flash[:warning] = "成功将 #{@product.title} 从购物车删除!"
redirect_to :back
end

def update
@cart = current_cart
@cart_item = @cart.cart_items.find_by(product_id: params[:id])

if @cart_item.product.quantity >= cart_item_params[:quantity].to_i
@cart_item.update(cart_item_params)
flash[:notice] = "成功变更数量"
else
flash[:warning] = "数量不足以加入购物车"
end


redirect_to carts_path
end

private

def cart_item_params
params.require(:cart_item).permit(:quantity)
end
end
12 changes: 12 additions & 0 deletions app/controllers/carts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CartsController < ApplicationController
before_action :authenticate_user!
def clean
current_cart.clean!
flash[:warning] = "已清空购物车"
redirect_to carts_path
end

def checkout
@order = Order.new
end
end
Loading