Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,27 @@ gem 'spring', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]


#customize gem
gem 'pry', '~> 0.10.0'
gem 'simple_form', '~> 3.0.2'
gem 'bootstrap-sass', '~> 3.2.0.0'
#The bootstrap-sass-rails gem is deprecated starting with version 3.1.0.0.
#gem 'bootstrap-sass-rails', '~> 3.1.0.0'
gem 'will_paginate' , '~> 3.0'
gem 'will_paginate-bootstrap'
gem 'devise' , '~> 3.2'
gem 'carrierwave'
gem 'cocoon', '~> 1.2.6'

group :developmet, :test do
gem 'guard-livereload'
gem 'annotate', '~> 2.6.5'
gem 'mysql2'
end






74 changes: 74 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,56 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
annotate (2.6.5)
activerecord (>= 2.3.0)
rake (>= 0.8.7)
arel (5.0.1.20140414130214)
bcrypt (3.1.7)
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)
celluloid (0.15.2)
timers (~> 1.1.0)
cocoon (1.2.6)
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)
devise (3.2.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
thread_safe (~> 0.1)
warden (~> 1.2.3)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
erubis (2.7.0)
eventmachine (1.0.3)
execjs (2.2.0)
ffi (1.9.3)
formatador (0.2.5)
guard (2.6.1)
formatador (>= 0.2.4)
listen (~> 2.7)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-livereload (2.3.0)
em-websocket (~> 0.5)
guard (~> 2.0)
multi_json (~> 1.8)
hike (1.2.3)
http_parser.rb (0.6.0)
i18n (0.6.9)
jbuilder (2.0.8)
activesupport (>= 3.0.0, < 5)
Expand All @@ -47,13 +85,25 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
listen (2.7.9)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.9)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.25.1)
minitest (5.3.4)
multi_json (1.10.1)
mysql2 (0.3.16)
orm_adapter (0.5.0)
polyglot (0.3.5)
pry (0.10.0)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
Expand All @@ -73,6 +123,9 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rdoc (4.1.1)
json (~> 1.4)
sass (3.2.19)
Expand All @@ -84,6 +137,10 @@ GEM
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
simple_form (3.0.2)
actionpack (~> 4.0)
activemodel (~> 4.0)
slop (3.5.0)
spring (1.1.3)
sprockets (2.11.0)
hike (~> 1.2)
Expand All @@ -98,6 +155,7 @@ GEM
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
timers (1.1.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -108,18 +166,34 @@ GEM
uglifier (2.5.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
warden (1.2.3)
rack (>= 1.0)
will_paginate (3.0.7)
will_paginate-bootstrap (1.0.1)
will_paginate (>= 3.0.3)

PLATFORMS
ruby

DEPENDENCIES
annotate (~> 2.6.5)
bootstrap-sass (~> 3.2.0.0)
carrierwave
cocoon (~> 1.2.6)
coffee-rails (~> 4.0.0)
devise (~> 3.2)
guard-livereload
jbuilder (~> 2.0)
jquery-rails
mysql2
pry (~> 0.10.0)
rails (= 4.1.0)
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
simple_form (~> 3.0.2)
spring
sqlite3
turbolinks
uglifier (>= 1.3.0)
will_paginate (~> 3.0)
will_paginate-bootstrap
11 changes: 11 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end
Empty file removed README.md
Empty file.
9 changes: 9 additions & 0 deletions app/assets/javascripts/admin/jquery_customization.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$(document).on('ready page:load', function(){


$("div.item:first-child").addClass("active");

//var tmpl = '<div class="input file optional photo_image form-group"><label class="file optional" for="photo_image">上傳圖片</label><input class="file optional form-control" id="photo_image" name="photo[image]" type="file"></div><label class="file optional" for="photo_image">上傳圖片</label><input class="file optional form-control" id="photo_image" name="photo[image]" type="file"></div>'


});
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/photos.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-sprockets
//= require cocoon
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/photos.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin::photos 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/
28 changes: 28 additions & 0 deletions app/assets/stylesheets/bootstrap_and_customization.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@import 'bootstrap';



.center {
text-align: center;
}

/* why does this css not work? */
.img-box img {
width: 100%;
height: 261px;
}


.carousel-inner .img-box img{
width: 100%;
height: 261px;

}


.form-img-box img{
width: 40px;
height: 40px;

}

31 changes: 31 additions & 0 deletions app/controllers/admin/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Admin::PhotosController < ApplicationController

def new
#@photo = Photo.new
@product = Product.find(params[:product_id])
@photo = @product.photos.build
end

def create
#@photo = Photo.new(photo_params)
@product = Product.find(params[:product_id])
@photo = @product.photos.build(photo_params)
if @photo.save
redirect_to admin_product_path(@product)
end
end

def index
@photos = Photo.all
end



private

def photo_params
params.require(:photo).permit(:image)
end


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

#the order is important, you should confirm current_user is exit brfore called admin_required
before_action :authenticate_user!
before_action :admin_required, :except => [:index]
before_action :find_product, :only => [:show, :edit, :update, :destroy]


def index
@products = Product.all.order("created_at DESC").paginate(:page => params[:page], :per_page=>20)
end

def show
@photos = @product.photos
end

def new
@product = Product.new
@product.photos.build

end

def create
@product = Product.new(product_params)

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

def edit
end

def update
if @product.update(product_params)
redirect_to admin_products_path
else
render :edit
end

end

def destroy
if @product.destroy
redirect_to admin_products_path
end
end



private

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

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


end
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ 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
redirect_to root_path if !current_user.admin?
end
end
2 changes: 2 additions & 0 deletions app/helpers/admin/photos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::PhotosHelper
end
2 changes: 2 additions & 0 deletions app/helpers/admin/products_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::ProductsHelper
end
15 changes: 15 additions & 0 deletions app/models/photo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# == Schema Information
#
# Table name: photos
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
# image :string(255)
# product_id :integer
#

class Photo < ActiveRecord::Base
mount_uploader :image, ImageUploader
belongs_to :product
end
17 changes: 17 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: products
#
# id :integer not null, primary key
# title :string(255)
# description :text
# quantity :integer
# created_at :datetime
# updated_at :datetime
#

class Product < ActiveRecord::Base
has_many :photos, :dependent => :delete_all

accepts_nested_attributes_for :photos, :reject_if => :all_blank, allow_destroy: true
end
Loading