Commit 96fc05a1 by vulehuan

code breadcrumb

parent e019b632
...@@ -55,3 +55,4 @@ end ...@@ -55,3 +55,4 @@ end
gem 'will_paginate', '3.0.4' gem 'will_paginate', '3.0.4'
gem 'will_paginate-bootstrap' gem 'will_paginate-bootstrap'
gem 'recaptcha-mailhide' gem 'recaptcha-mailhide'
gem "breadcrumbs_on_rails"
\ No newline at end of file
...@@ -28,6 +28,7 @@ GEM ...@@ -28,6 +28,7 @@ GEM
arel (4.0.1) arel (4.0.1)
atomic (1.1.14) atomic (1.1.14)
bcrypt-ruby (3.0.1) bcrypt-ruby (3.0.1)
breadcrumbs_on_rails (2.3.0)
builder (3.1.4) builder (3.1.4)
capybara (2.1.0) capybara (2.1.0)
mime-types (>= 1.16) mime-types (>= 1.16)
...@@ -144,6 +145,7 @@ PLATFORMS ...@@ -144,6 +145,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
bcrypt-ruby (~> 3.0.0) bcrypt-ruby (~> 3.0.0)
breadcrumbs_on_rails
capybara capybara
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
factory_girl_rails factory_girl_rails
......
...@@ -3,4 +3,6 @@ class ApplicationController < ActionController::Base ...@@ -3,4 +3,6 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
include SessionsHelper include SessionsHelper
add_breadcrumb "Home", :root_path
end end
class ProductCategoriesController < ApplicationController class ProductCategoriesController < ApplicationController
add_breadcrumb "Products", :products_path
def show def show
term = ProductCategory.find(params[:id]) term = ProductCategory.find(params[:id])
if term == nil if term == nil
...@@ -7,6 +9,7 @@ class ProductCategoriesController < ApplicationController ...@@ -7,6 +9,7 @@ class ProductCategoriesController < ApplicationController
else else
@items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 16) @items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 16)
@title = term.name @title = term.name
add_breadcrumb term.name, product_category_path(term)
end end
end end
end end
class ProductsController < ApplicationController class ProductsController < ApplicationController
add_breadcrumb "Products", :products_path
def index def index
@products = Product.get_list(limit: 16, page: params[:page])
end end
def show def show
@product = Product.find(params[:id]) @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) @other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 16)
end end
end end
...@@ -32,4 +32,14 @@ class Product < ActiveRecord::Base ...@@ -32,4 +32,14 @@ class Product < ActiveRecord::Base
.order('created_at DESC').order('updated_at DESC').order('name') .order('created_at DESC').order('updated_at DESC').order('name')
.limit(limit) .limit(limit)
end 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 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
...@@ -31,10 +31,7 @@ ...@@ -31,10 +31,7 @@
<%= render 'layouts/slide' %> <%= render 'layouts/slide' %>
<nav class="breadcrumb"> <nav class="breadcrumb">
<span>You are in: </span> <span>You are in: </span>
<ul> <%= render_breadcrumbs %>
<li><a href="">Home</a></li>
<li class="last"><a href="">Lorem Ipsum</a></li>
</ul>
</nav> </nav>
<div class="clearfix"></div> <div class="clearfix"></div>
<% if flash.any? %> <% if flash.any? %>
......
...@@ -21,13 +21,7 @@ ...@@ -21,13 +21,7 @@
<%= render 'layouts/header' %> <%= render 'layouts/header' %>
</div> </div>
<div class="container"> <div class="container">
<nav class="breadcrumb"> <%= render 'layouts/breadcrumb', breadcrumbs: yield(:breadcrumbs) %>
<span>You are in: </span>
<ul>
<li><a href="">Home</a></li>
<li class="last"><a href="">Lorem Ipsum</a></li>
</ul>
</nav>
<div class="clearfix"></div> <div class="clearfix"></div>
<% if flash.any? %> <% if flash.any? %>
<div id="block-message" class="hidden"> <div id="block-message" class="hidden">
......
<% provide(:title, @title) %> <% provide(:title, @title) %>
<!-- Recommended Items -->
<div class="body-box grid-view"> <div class="body-box grid-view">
<h2 class="sprite-2"> <h2 class="sprite-2">
<%= @title %><span class="sprite-2"></span> <%= @title %><span class="sprite-2"></span>
......
<% provide(:title, "Products") %> <% provide(:title, "Products") %>
<h1>Products#index</h1> <div class="body-box grid-view">
<p>Find me in app/views/products/index.html.erb</p> <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