Commit 96fc05a1 by vulehuan

code breadcrumb

parent e019b632
......@@ -54,4 +54,5 @@ group :test do
end
gem 'will_paginate', '3.0.4'
gem 'will_paginate-bootstrap'
gem 'recaptcha-mailhide'
\ No newline at end of file
gem 'recaptcha-mailhide'
gem "breadcrumbs_on_rails"
\ No newline at end of file
......@@ -28,6 +28,7 @@ GEM
arel (4.0.1)
atomic (1.1.14)
bcrypt-ruby (3.0.1)
breadcrumbs_on_rails (2.3.0)
builder (3.1.4)
capybara (2.1.0)
mime-types (>= 1.16)
......@@ -144,6 +145,7 @@ PLATFORMS
DEPENDENCIES
bcrypt-ruby (~> 3.0.0)
breadcrumbs_on_rails
capybara
coffee-rails (~> 4.0.0)
factory_girl_rails
......
......@@ -3,4 +3,6 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
add_breadcrumb "Home", :root_path
end
class ProductCategoriesController < ApplicationController
add_breadcrumb "Products", :products_path
def show
term = ProductCategory.find(params[:id])
if term == nil
......@@ -7,6 +9,7 @@ class ProductCategoriesController < ApplicationController
else
@items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 16)
@title = term.name
add_breadcrumb term.name, product_category_path(term)
end
end
end
class ProductsController < ApplicationController
add_breadcrumb "Products", :products_path
def index
@products = Product.get_list(limit: 16, page: params[:page])
end
def show
@product = Product.find(params[:id])
Please register or sign in to reply
product_category = ProductCategory.find(@product.product_category_id)
if product_category != nil
Please register or sign in to reply
add_breadcrumb product_category.name, product_category_path(product_category)
add_breadcrumb @product.name, product_path(@product)
end
@other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 16)
end
end
......@@ -32,4 +32,14 @@ class Product < ActiveRecord::Base
.order('created_at DESC').order('updated_at DESC').order('name')
.limit(limit)
end
# Returns products list
def self.get_list(options = { limit: 16 })
limit = options[:limit]
page = options[:page]
return Product.select('id, name, image_medium, price, price_currency')
.where(availability: 'instock')
.paginate(:page => page, :per_page => limit)
.order('created_at DESC').order('updated_at DESC').order('name')
end
end
\ No newline at end of file
<nav class="breadcrumb">
<span>You are in: </span>
<ul>
<%
if breadcrumbs == nil || breadcrumbs.empty?
breadcrumbs = Array.new
breadcrumbs.push({ text: 'Home', url: root_path })
else
breadcrumbs.unshift({ text: 'Home', url: root_path })
end
i = 1
n = breadcrumbs.count
breadcrumbs.each do |breadcrumb|
%>
<li<%= raw %Q{ class="last"} if i == n %>><a href="<%= breadcrumb[:url] %>"><%= breadcrumb[:text] %></a></li>
<%
i += 1
end
%>
</ul>
</nav>
\ No newline at end of file
......@@ -28,13 +28,10 @@
<%= render 'layouts/advertising' %>
</div>
<div class="col-md-9 col-sm-9">
<%= render 'layouts/slide' %>
<%= render 'layouts/slide' %>
  • dùng render partial, chỉ rõ path, ví dụ: <%=render :partial => "/jobs/show", :locals => {:job => @job} %>

Please register or sign in to reply
<nav class="breadcrumb">
<span>You are in: </span>
<ul>
<li><a href="">Home</a></li>
<li class="last"><a href="">Lorem Ipsum</a></li>
</ul>
<%= render_breadcrumbs %>
</nav>
<div class="clearfix"></div>
<% if flash.any? %>
......
......@@ -21,13 +21,7 @@
<%= render 'layouts/header' %>
</div>
<div class="container">
<nav class="breadcrumb">
<span>You are in: </span>
<ul>
<li><a href="">Home</a></li>
<li class="last"><a href="">Lorem Ipsum</a></li>
</ul>
</nav>
<%= render 'layouts/breadcrumb', breadcrumbs: yield(:breadcrumbs) %>
<div class="clearfix"></div>
<% if flash.any? %>
<div id="block-message" class="hidden">
......
<% provide(:title, @title) %>
<!-- Recommended Items -->
<div class="body-box grid-view">
<h2 class="sprite-2">
<%= @title %><span class="sprite-2"></span>
......
<% provide(:title, "Products") %>
<h1>Products#index</h1>
<p>Find me in app/views/products/index.html.erb</p>
<div class="body-box grid-view">
<h2 class="sprite-2">
Products<span class="sprite-2"></span>
</h2>
<%= render 'shared/grid', items: @products %>
<%= will_paginate @products, renderer: BootstrapPagination::Rails %>
<div class="clearfix"></div>
</div>
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