Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store v2 #29

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
711c476
add admin/products
jimmy0328 Jul 10, 2014
ff5d375
add admin prodcuts to routes
jimmy0328 Jul 10, 2014
d8c1e15
add product model
jimmy0328 Jul 10, 2014
c4dc95f
db:migrate
jimmy0328 Jul 10, 2014
6f54471
add new&show method in controller
jimmy0328 Jul 10, 2014
6fc4dd8
add index
jimmy0328 Jul 10, 2014
ae05833
add devise Gem and add auth
jimmy0328 Jul 10, 2014
e24ef1e
add bootstrap gem
jimmy0328 Jul 10, 2014
74b1516
add carrierwave Gem and mini_magick Gem
jimmy0328 Jul 10, 2014
f7d83b9
image upload and navigation layout
jimmy0328 Jul 10, 2014
6f2a83d
add gitignore -- config/image
jimmy0328 Jul 10, 2014
58348f1
增加前台畫面
jimmy0328 Jul 10, 2014
4804419
delete images
jimmy0328 Jul 10, 2014
8d0c44e
add admin/product destory function
jimmy0328 Jul 11, 2014
0a30f06
modify show page
jimmy0328 Jul 11, 2014
9f9f91a
alter table price and quantity column
jimmy0328 Jul 11, 2014
c88b275
add price column to product
jimmy0328 Jul 11, 2014
da5a68f
refactor simple_form_for ui and resize image size
jimmy0328 Jul 11, 2014
0230cc3
add font awesome
jimmy0328 Jul 14, 2014
0052a3f
add multi photos
jimmy0328 Jul 14, 2014
67e4fa4
temp
jimmy0328 Jul 16, 2014
645a442
add product to cart
jimmy0328 Jul 16, 2014
d37206f
add user cart detail page
jimmy0328 Jul 16, 2014
5165322
填寫寄送資訊 及 信⽤用卡結帳
jimmy0328 Jul 17, 2014
d388cb4
add assm
jimmy0328 Jul 17, 2014
fd4dec6
清空購物車
jimmy0328 Jul 17, 2014
0f4b7b6
add homework1
jimmy0328 Jul 18, 2014
de20b34
add account/orders history
jimmy0328 Jul 20, 2014
14a3b3e
使用者可以看到過去的訂單
jimmy0328 Jul 23, 2014
a128e46
fix bug
jimmy0328 Jul 23, 2014
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
/public/uploads/*
20 changes: 20 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development


gem 'devise'
gem 'bootstrap-sass'
gem "font-awesome-rails"

gem 'carrierwave'
gem "mini_magick"


gem 'simple_form'
gem 'aasm'

#debug
gem 'binding_of_caller'
gem 'better_errors'





# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

Expand Down
42 changes: 42 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
aasm (3.2.0)
actionmailer (4.1.0)
actionpack (= 4.1.0)
actionview (= 4.1.0)
Expand Down Expand Up @@ -28,16 +29,39 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bcrypt (3.1.7)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.2.0.0)
sass (~> 3.2)
builder (3.2.2)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.7.0)
debug_inspector (0.0.2)
devise (3.2.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
thread_safe (~> 0.1)
warden (~> 1.2.3)
erubis (2.7.0)
execjs (2.2.0)
font-awesome-rails (4.1.0.0)
railties (>= 3.2, < 5.0)
hike (1.2.3)
i18n (0.6.9)
jbuilder (2.0.8)
Expand All @@ -51,8 +75,11 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
mini_magick (3.7.0)
subexec (~> 0.2.1)
minitest (5.3.4)
multi_json (1.10.1)
orm_adapter (0.5.0)
polyglot (0.3.5)
rack (1.5.2)
rack-test (0.6.2)
Expand Down Expand Up @@ -84,6 +111,9 @@ GEM
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
simple_form (3.0.2)
actionpack (~> 4.0)
activemodel (~> 4.0)
spring (1.1.3)
sprockets (2.11.0)
hike (~> 1.2)
Expand All @@ -95,6 +125,7 @@ GEM
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.9)
subexec (0.2.3)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
Expand All @@ -108,17 +139,28 @@ GEM
uglifier (2.5.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
warden (1.2.3)
rack (>= 1.0)

PLATFORMS
ruby

DEPENDENCIES
aasm
better_errors
binding_of_caller
bootstrap-sass
carrierwave
coffee-rails (~> 4.0.0)
devise
font-awesome-rails
jbuilder (~> 2.0)
jquery-rails
mini_magick
rails (= 4.1.0)
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
simple_form
spring
sqlite3
turbolinks
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/account/orderitems.js.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/account/orders.js.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/orderitems.js.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/orders.js.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.js.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

3 changes: 3 additions & 0 deletions app/assets/javascripts/carts.js.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.js.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/orderitems.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the account::orderitems 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/account/orders.css.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/orderitems.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin::orderitems 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/orders.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin::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.css.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/
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
*
*= require_tree .
*= require_self
*= require bootstrap
*= require font-awesome
*/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/carts.css.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.css.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/
10 changes: 10 additions & 0 deletions app/controllers/account/orderitems_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Account::OrderitemsController < ApplicationController
before_action :authenticate_user!

def show
@orders = Order.find(params[:id])
@order_info = @orders.info
@items = @orders.items
end

end
12 changes: 12 additions & 0 deletions app/controllers/account/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Account::OrdersController < ApplicationController
before_action :authenticate_user!

def index
@order = current_user.orders.recent
end

def show
#@order = Order.items.where(id: params[:id])
end

end
13 changes: 13 additions & 0 deletions app/controllers/admin/orderitems_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Admin::OrderitemsController < ApplicationController

before_action :authenticate_user!
before_action :admin_required

def show
@orders = Order.find(params[:id])
@order_info = @orders.info
@items = @orders.items
end


end
42 changes: 42 additions & 0 deletions app/controllers/admin/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Admin::OrdersController < ApplicationController

before_action :authenticate_user!
before_action :admin_required
before_filter :find_order, :except => [:index]

def index
@order = Order.recent
end

def show
@order_info = @order.info
@order_items = @order.items
end

def ship
@order.ship!
redirect_to :back
end

def shipped
@order.deliver!
redirect_to :back
end

def cancel
@order.cancell_order!
redirect_to :back
end

def return
@order.return_good!
redirect_to :back
end

protected
def find_order
@order = Order.find_by_token(params[:id])
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!
before_action :admin_required


def index
@products = Product.all
end

def new
@product = Product.new
@photo = @product.photos.new
end

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

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

def update
@product = Product.find(params[:id])
if @product.update(product_params)
redirect_to admin_products_path
else
render :edit
end
end


def destroy
@product = Product.find(params[:id])
@product.destroy!
redirect_to admin_products_path
end

def create
@product = Product.new(product_params)
if @product.save
redirect_to admin_products_path
else
render :new
end
end

private

def product_params
#params.require(:product).permit(:title,:description,:quantity, :price, :image)
params.require(:product).permit(:title,:description,:quantity, :price, :photos_attributes => [:image])
end


end
23 changes: 23 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,27 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def admin_required
current_user.is_admin?
end

helper_method :current_cart

def current_cart
@current_cart ||= find_Cart
end

def find_Cart
cart = Cart.find_by(id: session[:cart_id])

unless cart.present?
cart = Cart.create
end

session[:cart_id] = cart.id
cart

end

end
Loading