From 6e8e5e88e7289f09a53c0641c1264626a6ad50c9 Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:15:39 +0800 Subject: [PATCH 01/34] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20application.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/application.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a830..3e44c7452 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,4 +13,5 @@ //= require jquery //= require jquery_ujs //= require turbolinks +//= require bootstrap/dropdown //= require_tree . From aca50c25ee51a2062256a5ebc2cff348b0ace1ef Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:16:46 +0800 Subject: [PATCH 02/34] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20partial:=20navbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/common/_navbar.html.erb | 36 ++++++++++++++++++++++++++ app/views/layouts/application.html.erb | 11 +++----- 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 app/views/common/_navbar.html.erb diff --git a/app/views/common/_navbar.html.erb b/app/views/common/_navbar.html.erb new file mode 100644 index 000000000..36a80ab82 --- /dev/null +++ b/app/views/common/_navbar.html.erb @@ -0,0 +1,36 @@ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ac224341a..5d5782a99 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,13 +8,10 @@ - <% if !current_user %> - <%= link_to("登入", new_user_session_path) %> - <% else %> - <%= link_to("登出", destroy_user_session_path, method: :delete) %> - <% end %> - -<%= yield %> +
+ <%= render "common/navbar" %> + <%= yield %> +
From 7a28add9dbd1cc9454941f4079b34bd839085596 Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:17:13 +0800 Subject: [PATCH 03/34] rails g controller products --- app/assets/javascripts/products.coffee | 3 +++ app/assets/stylesheets/products.scss | 3 +++ app/controllers/products_controller.rb | 2 ++ app/helpers/products_helper.rb | 2 ++ test/controllers/products_controller_test.rb | 7 +++++++ 5 files changed, 17 insertions(+) create mode 100644 app/assets/javascripts/products.coffee create mode 100644 app/assets/stylesheets/products.scss create mode 100644 app/controllers/products_controller.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 test/controllers/products_controller_test.rb diff --git a/app/assets/javascripts/products.coffee b/app/assets/javascripts/products.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/app/assets/javascripts/products.coffee @@ -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/ diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 000000000..89e2e8db0 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -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/ diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 000000000..f1ad12dde --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,2 @@ +class ProductsController < ApplicationController +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 000000000..ab5c42b32 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 000000000..c881fa681 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end From 83f84acfe53e1bd299e212b6124c28203c0dc78c Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:18:08 +0800 Subject: [PATCH 04/34] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E7=A9=BA=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E5=8F=B0=E9=A6=96=E9=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/common/_navbar.html.erb | 2 +- app/views/products/index.html.erb | 0 config/routes.rb | 5 +++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 app/views/products/index.html.erb diff --git a/app/views/common/_navbar.html.erb b/app/views/common/_navbar.html.erb index 36a80ab82..f4b0486e8 100644 --- a/app/views/common/_navbar.html.erb +++ b/app/views/common/_navbar.html.erb @@ -9,7 +9,7 @@ + <% if @photo.image.present? %> + 目前商品圖
+ <%= image_tag(@photo.image.thumb.url) %> + <% end %> + +
+ <%= f.simple_fields_for :photo do |c| %> + <%= c.input :image , as: :file %> + <% end %> +
+ <%= f.submit "Submit", data: { disable_with: "Submitting..." } %> <% end %> From 4e1e7b19ec3b1509c5f3e688957b23df46bbd766 Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:35:18 +0800 Subject: [PATCH 18/34] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E5=95=86=E5=93=81=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/products_controller.rb | 3 +++ app/views/products/index.html.erb | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index f1ad12dde..b93cd40f5 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,2 +1,5 @@ class ProductsController < ApplicationController + def index + @products = Product.all + end end diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index e69de29bb..842adaf34 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -0,0 +1,14 @@ +
+ <% @products.each do |product| %> +
+ <%= link_to product_path(product) do %> + <% if product.photo.present? %> + <%= image_tag(product.photo.image.thumb.url, class: "thumbnail") %> + <% else %> + <%= image_tag("http://placehold.it/200x200&text=No Pic", class: "thumbnail") %> + <% end %> + <% end %> + <%= product.title %> $ <%= product.price %> +
+ <% end %> +
From d397de189fe7b7efa00623a42b1d1a5345407a86 Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:36:49 +0800 Subject: [PATCH 19/34] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E5=95=86=E5=93=81=20show?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/products_controller.rb | 4 ++++ app/views/products/show.html.erb | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/views/products/show.html.erb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index b93cd40f5..0e295c258 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -2,4 +2,8 @@ class ProductsController < ApplicationController def index @products = Product.all end + + def show + @product = Product.find(params[:id]) + end end diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 000000000..f698e096b --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,22 @@ +
+
+ <% if @product.photo.present? %> + <%= image_tag(@product.photo.image.medium.url, class: "thumbnail") %> + <% else %> + <%= image_tag("http://placehold.it/400x400&text=No Pic", class: "thumbnail") %> + <% end %> +
+
+

<%= @product.title %>

+
+

+ <%= @product.description %> +

+
+
數量 : <%= @product.quantity %>
+
$ <%= @product.price %>
+
+ <%= link_to("加入購物車", "#", :class => "btn btn-primary btn-lg btn-danger") %> +
+
+
From 839b10206a30a755a1d66110d2ac8f65463dc549 Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:37:54 +0800 Subject: [PATCH 20/34] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=20layout:=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/products_controller.rb | 2 ++ app/views/layouts/admin.html.erb | 24 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/views/layouts/admin.html.erb diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb index 9d5d751ad..7b736c44f 100644 --- a/app/controllers/admin/products_controller.rb +++ b/app/controllers/admin/products_controller.rb @@ -1,5 +1,7 @@ class Admin::ProductsController < ApplicationController + layout "admin" + before_action :authenticate_user! before_action :admin_required diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb new file mode 100644 index 000000000..e3bf7ba4d --- /dev/null +++ b/app/views/layouts/admin.html.erb @@ -0,0 +1,24 @@ + + + + Artstore 後台 + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + +
+ <%= render "common/navbar" %> +
+
+ +
+
+ <%= yield %> +
+
+
+ + From d908dfbd75ced371d9444f52a6047c9d389454d1 Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:38:40 +0800 Subject: [PATCH 21/34] =?UTF-8?q?=E9=87=8D=E6=A7=8B=E5=BE=8C=E5=8F=B0?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admin/products/index.html.erb | 48 +++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/app/views/admin/products/index.html.erb b/app/views/admin/products/index.html.erb index 1cc1d7c87..5cacbf0aa 100644 --- a/app/views/admin/products/index.html.erb +++ b/app/views/admin/products/index.html.erb @@ -1,6 +1,42 @@ -
    - <% @products.each do |product| %> - -
  • <%= link_to(product.title, admin_product_path(product)) %>
  • - <% end %> -
+

Product List

+
+ <%= link_to("新增產品", new_admin_product_path, class: "btn btn-primary btn-sm") %> +
+ + + + + + + + + + + + <% @products.each do |product| %> + + + + + + + + <% end %> + +
#Product PicNamePrice Options
+ <%= product.id %> + + <%= link_to product_path(product) do %> + <% if product.photo.present? %> + <%= image_tag(product.photo.image.thumb.url, class: "thumbnail") %> + <% else %> + <%= image_tag("http://placehold.it/200x200&text=No Pic", class: "thumbnail") %> + <% end %> + <% end %> + + <%= product.title %> + + <%= product.price %> + + <%= link_to("Edit", edit_admin_product_path(product)) %> +
From 1a826b5bfe6d6e68272355e39c3b7a0873fc66bf Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:39:37 +0800 Subject: [PATCH 22/34] =?UTF-8?q?navbar=20=E7=9A=84=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E9=81=B8=E5=96=AE=E6=94=BE=E5=85=A5=E5=BE=8C=E5=8F=B0=E9=80=A3?= =?UTF-8?q?=E7=B5=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/common/_navbar.html.erb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/views/common/_navbar.html.erb b/app/views/common/_navbar.html.erb index f4b0486e8..a4409bc69 100644 --- a/app/views/common/_navbar.html.erb +++ b/app/views/common/_navbar.html.erb @@ -23,6 +23,13 @@
+ <%= notice_message %> <%= yield %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5d5782a99..6e0218b4e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,7 @@
<%= render "common/navbar" %> + <%= notice_message %> <%= yield %>
From 493b3622b228af0a1a89b36dcc7b43c6951527fd Mon Sep 17 00:00:00 2001 From: sdlong Date: Tue, 8 Mar 2016 15:41:29 +0800 Subject: [PATCH 24/34] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E8=B3=BC=E7=89=A9?= =?UTF-8?q?=E8=BB=8A=E6=8C=89=E9=88=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/common/_navbar.html.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/views/common/_navbar.html.erb b/app/views/common/_navbar.html.erb index a4409bc69..1b9daa194 100644 --- a/app/views/common/_navbar.html.erb +++ b/app/views/common/_navbar.html.erb @@ -13,6 +13,11 @@