diff --git a/app/assets/images/products/digital_20.jpg b/app/assets/images/products/digital_20.jpg new file mode 100644 index 0000000..e8e2908 Binary files /dev/null and b/app/assets/images/products/digital_20.jpg differ diff --git a/app/assets/images/shop-banner.jpg b/app/assets/images/shop-banner.jpg new file mode 100644 index 0000000..98d77bc Binary files /dev/null and b/app/assets/images/shop-banner.jpg differ diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..32a6960 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,8 @@ +class ProductsController < ApplicationController + def index + @pagy, @products = pagy Product.sort_by_price, + items: Settings.length.per_page_12 + end + + def show; end +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000..ab5c42b --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/models/product.rb b/app/models/product.rb index ee0d335..8c60c8e 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -2,4 +2,5 @@ class Product < ApplicationRecord belongs_to :category has_many :order_details, dependent: :destroy has_many :comments, dependent: :destroy + scope :sort_by_price, ->{order :price} end diff --git a/app/views/products/_product.html.erb b/app/views/products/_product.html.erb new file mode 100644 index 0000000..98ba212 --- /dev/null +++ b/app/views/products/_product.html.erb @@ -0,0 +1,18 @@ +
  • +
    +
    + <%= link_to product do %> +
    + <%= image_tag(product.image, alt: "") %> +
    + <% end %> +
    +
    + <%= link_to product, class: "product-name" do %> + <%= product.name %> + <% end %> +
    <%= product.price %>
    + <%= link_to t(".add_to_cart"), product, class: "btn add-to-cart" %> +
    +
    +
  • diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000..dfbb2bb --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,59 @@ +<% provide :title, t(".title") %> +
    + +
    +
    +
    +
    +

    <%= t ".all_categories" %>

    +
    +
      +
    • + <%= link_to t(".category"), "#", class: "cate-link" %> + + +
        +
      • <%= link_to t(".sub_category"), "#", class: "cate-link" %>
      • +
      +
    • +
    • + <%= link_to t(".category"), "#", class: "cate-link" %> +
    • +
    +
    +
    +
    +

    <%= t ".price" %>

    +
    +
    +

    + + + +

    +
    +
    +
    +
    + +
    +

    <%= t ".digital_electronic" %>

    +
    +
    +
      + <%= render @products %> +
    +
    +
    +
      + <%== pagy_bootstrap_nav(@pagy) %> +
    +
    +
    +
    diff --git a/app/views/shared/_error_messages.html.erb b/app/views/shared/_error_messages.html.erb index d78ae3b..6e06fcf 100644 --- a/app/views/shared/_error_messages.html.erb +++ b/app/views/shared/_error_messages.html.erb @@ -2,7 +2,7 @@
    <%= t "the_form_contains" %> - <%= t "errors.error_message", count: pluralize(@user.errors.count, t("errors.error_singular")) %> + <%= t "errors.error_message", count: pluralize(object.errors.count, t("errors.error_singular")) %>