forked from awesome-academy/dn_fresher_haikhanh_ecomerces
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request awesome-academy#7 from hainv-2854/user_show_product
User: Show products
- Loading branch information
Showing
16 changed files
with
207 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ProductsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<li class="col-lg-4 col-md-6 col-sm-6 col-xs-6 "> | ||
<div class="product product-style-3 equal-elem "> | ||
<div class="product-thumnail"> | ||
<%= link_to product do %> | ||
<figure> | ||
<%= image_tag(product.image, alt: "") %> | ||
</figure> | ||
<% end %> | ||
</div> | ||
<div class="product-info"> | ||
<%= link_to product, class: "product-name" do %> | ||
<span><%= product.name %></span> | ||
<% end %> | ||
<div class="wrap-price"><span class="product-price"><span><%= product.price %></span></div> | ||
<%= link_to t(".add_to_cart"), product, class: "btn add-to-cart" %> | ||
</div> | ||
</div> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<% provide :title, t(".title") %> | ||
<div class="wrap-breadcrumb"> | ||
<ul> | ||
<li class="item-link"><%= link_to t(".sub_category"), "#", class: "link" %></li> | ||
<li class="item-link"><span><%= t ".digital_electronic" %></span></li> | ||
</ul> | ||
</div> | ||
<div class="row"> | ||
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12 sitebar"> | ||
<div class="widget mercado-widget categories-widget"> | ||
<h2 class="widget-title"><%= t ".all_categories" %></h2> | ||
<div class="widget-content"> | ||
<ul class="list-category"> | ||
<li class="category-item has-child-cate"> | ||
<%= link_to t(".category"), "#", class: "cate-link" %> | ||
<span class="toggle-control">+</span> | ||
<ul class="sub-cate"> | ||
<li class="category-item"><%= link_to t(".sub_category"), "#", class: "cate-link" %></li> | ||
</ul> | ||
</li> | ||
<li class="category-item"> | ||
<%= link_to t(".category"), "#", class: "cate-link" %> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="widget mercado-widget filter-widget price-filter"> | ||
<h2 class="widget-title"><%= t ".price" %></h2> | ||
<div class="widget-content"> | ||
<div id="slider-range"></div> | ||
<p> | ||
<label for="amount"><%= t ".price" %> :</label> | ||
<input type="text" id="amount" readonly> | ||
<button class="filter-submit"><%= t ".filter" %></button> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-lg-9 col-md-8 col-sm-8 col-xs-12 main-content-area"> | ||
<div class="banner-shop"> | ||
<%= link_to "#", class: "banner-link" do %> | ||
<figure><%= image_tag("shop-banner.jpg", alt: "") %></figure> | ||
<% end %> | ||
</div> | ||
<div class="wrap-shop-control"> | ||
<h1 class="shop-title"><%= t ".digital_electronic" %></h1> | ||
</div> | ||
<div class="row"> | ||
<ul class="product-list grid-products equal-container"> | ||
<%= render @products %> | ||
</ul> | ||
</div> | ||
<div class="wrap-pagination-info"> | ||
<ul class="page-numbers"> | ||
<%== pagy_bootstrap_nav(@pagy) %> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
regex: | ||
email: !ruby/regexp /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i | ||
length: | ||
per_page_12: 12 |
36 changes: 36 additions & 0 deletions
36
db/migrate/20220110025410_create_active_storage_tables.active_storage.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This migration comes from active_storage (originally 20170806125915) | ||
class CreateActiveStorageTables < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :active_storage_blobs do |t| | ||
t.string :key, null: false | ||
t.string :filename, null: false | ||
t.string :content_type | ||
t.text :metadata | ||
t.string :service_name, null: false | ||
t.bigint :byte_size, null: false | ||
t.string :checksum, null: false | ||
t.datetime :created_at, null: false | ||
|
||
t.index [ :key ], unique: true | ||
end | ||
|
||
create_table :active_storage_attachments do |t| | ||
t.string :name, null: false | ||
t.references :record, null: false, polymorphic: true, index: false | ||
t.references :blob, null: false | ||
|
||
t.datetime :created_at, null: false | ||
|
||
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true | ||
t.foreign_key :active_storage_blobs, column: :blob_id | ||
end | ||
|
||
create_table :active_storage_variant_records do |t| | ||
t.belongs_to :blob, null: false, index: false | ||
t.string :variation_digest, null: false | ||
|
||
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true | ||
t.foreign_key :active_storage_blobs, column: :blob_id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
email: "[email protected]", | ||
password: "user123", | ||
password_confirmation: "user123", | ||
is_role: 1, | ||
role: 1, | ||
activated: true | ||
) | ||
10.times do |n| | ||
|
@@ -16,3 +16,22 @@ | |
activated: true | ||
) | ||
end | ||
|
||
category = ["Dell", "HP", "Lenovo", "Macbook"] | ||
|
||
3.times do |n| | ||
Category.create(name: category[n]) | ||
end | ||
|
||
50.times do |n| | ||
category_id = 1 | ||
category_id = 2 if n > 25 | ||
product = Product.create( | ||
name: Faker::Name.first_name, | ||
category_id: category_id, | ||
price: 120000, | ||
quantity: 10, | ||
image: "products/digital_20.jpg", | ||
description: Faker::Lorem.sentence, | ||
) | ||
end |