Commit 30bbcb60 by Hoang Phuc Do

Refactor code - Fix pull request #1

parent 0f75f6bb
module ProductsHelper module ProductsHelper
def get_product_thumbnail(product, thumbnail_width, thumbnail_height) def get_product_thumbnail(product, thumbnail_width, thumbnail_height)
if product.image_url.present? product.image_url ||
product.image_url
else
"product/placeholder_#{thumbnail_width}x#{thumbnail_height}" "product/placeholder_#{thumbnail_width}x#{thumbnail_height}"
end
end end
end end
\ No newline at end of file
<%# Link to the "First" page
- available local variables
url: url to the first page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="first"> <li class="first">
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %> <%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %>
</li> </li>
<%# Non-link tag that stands for skipped pages...
- available local variables
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="dots"> <li class="dots">
<a href="#"><%= t('views.pagination.truncate').html_safe %></a> <a href="#"><%= t('views.pagination.truncate').html_safe %></a>
</li> </li>
<%# Link to the "Last" page
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="last"> <li class="last">
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %> <%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %>
</li> </li>
<%# Link to the "Next" page
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="next"> <li class="next">
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %> <%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
</li> </li>
<%# Link showing page number
- available local variables
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="page<%= ' active' if page.current? %>"> <li class="page<%= ' active' if page.current? %>">
<%= link_to page, url, opts = {:remote => remote, :class => 'page-link', :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %> <%= link_to page, url, opts = {:remote => remote, :class => page.current? ? 'active' : 'page-link', :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
</li> </li>
<%# The container tag
- available local variables
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside
-%>
<%= paginator.render do -%> <%= paginator.render do -%>
<nav aria-label="Page Navigation"> <nav aria-label="Page Navigation">
<ul class="pagination"> <ul class="pagination">
......
<%# Link to the "Previous" page
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="prev"> <li class="prev">
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %> <%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
</li> </li>
...@@ -9,14 +9,12 @@ ...@@ -9,14 +9,12 @@
</head> </head>
<body> <body>
<div id="wrapper"> <div id="main-container col2-left-layout">
<div class="main"> <div class="container">
<div class="container"> <%= yield %>
<%= yield %>
</div>
<!-- End .container -->
</div> </div>
<!-- End .main --> <!-- End .container -->
</div> </div>
<!-- End .main-container -->
</body> </body>
</html> </html>
<li class="product product-<%= product.id %>"> <li class="item">
<div class="product-image-area"> <div class="product-img">
<a href="#" class="product-image"> <a href="#">
<%= image_tag(get_product_thumbnail(product, 170, 204)) %> <figure>
<%= image_tag(get_product_thumbnail(product, 170, 204), class: "small-image") %>
</figure>
</a> </a>
</div> </div>
<div class="product-details-area"> <div class="product-shop">
<h2 class="product-title"><%= product.title %></h2> <h2 class="product-name"><%= product.title %></h2>
<div class="product-price-container"> <div class="price-box">
<span class="product-price"><%= product.price %></span> <div class="special-price">
<span class="price"><%= number_to_currency(product.price) %></span>
</div>
</div>
<div class="desc std">
<%= simple_format(product.description) %>
</div> </div>
<!-- End .product-price-container -->
<div class="product-short-desc"><%= product.description %></div>
</div> </div>
</li> </li>
<!-- End .product --> \ No newline at end of file
\ No newline at end of file
<ul class="products-grid">
<% @recommended_products.each do |product| %> <% @recommended_products.each do |product| %>
<div class="product-item"> <li class="item col-lg-4 col-md-4 col-sm-6 col-xs-6 ">
<div class="product product-<%= product.id %>"> <div class="product-item">
<div class="product-image-container"> <div class="item-inner">
<a href="#" class="product-image"> <div class="product-thumb">
<%= image_tag(get_product_thumbnail(product, 170, 204)) %> <figure>
</a> <a href="#">
</div> <%= image_tag(get_product_thumbnail(product, 170, 204)) %>
<div class="product-details-area"> </a>
<h2 class="product-title"><%= product.title %></h2> </figure>
<div class="product-price-container"> </div>
<span class="product-price"><%= product.price %></span> <div class="item-info">
<div class="info-inner">
<div class="item-title">
<%= link_to product.title, "#" %>
</div>
<div class="item-content">
<div class="item-price">
<div class="price-box">
<div class="regular-price">
<span class="price"><%= number_to_currency(product.price) %></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
<!-- End .product-price-container -->
</div> </div>
</div> </li>
<!-- End .product --> <% end %>
</div> </ul>
<% end %> \ No newline at end of file
\ No newline at end of file
<div class="row"> <div class="row">
<div class="col-md-9 col-md-push-3"> <div class="col-main col-sm-9 col-xs-12 col-sm-push-3">
<div class="category-header"> <div class="shop-inner">
<h2>Recommended Items</h2> <div class="page-title">
</div> <h1>Recommended Items</h1>
<div class="shop-row"> </div>
<div class="shop-container max-col-3"> <div class="product-grid-area">
<%= render 'products/recommended' %> <%= render 'products/recommended' %>
</div> </div>
</div>
<div class="category-header"> <div class="page-title">
<h2>Newest Items</h2> <h1>Newest Items</h1>
</div> </div>
<div class="shop-row"> <div class="product-list-area">
<div class="shop-container"> <ul id="products-list" class="products-list">
<ul class="products-list">
<%= render @latest_products %> <%= render @latest_products %>
</ul> </ul>
</div> </div>
</div>
<%= paginate @latest_products %> <div class="pagination-area">
<%= paginate @latest_products %>
</div>
</div>
</div> </div>
<!-- End .col-md-9 --> <aside class="sidebar col-sm-3 col-xs-12 col-sm-pull-9">
<div class="col-md-3 col-md-pull-9 sidebar">
<%= render 'shared/sidebar' %> <%= render 'shared/sidebar' %>
</div> </aside>
</div> </div>
<!-- End .row -->
...@@ -5,7 +5,7 @@ class CreateProducts < ActiveRecord::Migration[5.1] ...@@ -5,7 +5,7 @@ class CreateProducts < ActiveRecord::Migration[5.1]
t.text :description t.text :description
t.text :sku t.text :sku
t.decimal :price, precision: 8, scale: 2 t.decimal :price, precision: 8, scale: 2
t.references :category, foreign_key: true t.references :category, index: true
t.timestamps t.timestamps
end end
end end
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first) # Character.create(name: 'Luke', movie: movies.first)
# Delete all categories
Category.destroy_all
# Create Product Categories # Create Product Categories
4.times do |n| 4.times do |n|
title = "Category #{n}" title = "Category #{n}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment