2014-06-22 2 views
0

저는 초보 프로그래머입니다. Spree를 사용자 정의하여 웹 스토어를 구축하고 있습니다. 사이트 페이지에서 "추천"으로 지정된 제품 만 표시하는 홈 페이지를 갖기 위해 노력하고 있습니다 (사이트 관리자가 설정할 수있는 Taxon을 기반으로 함). 그러나, 내가 발견 한 문제는 "추천"으로 지정된 모든 제품이 내 사이트에 두 번 나타납니다. 왜 이런 일이 벌어지고 있는지 전혀 알 수 없습니다.Spree 사용자 정의 사이트에 나열된 중복 제품 항목

다음
module Spree 
    class HomeController < Spree::StoreController 
    helper 'spree/products' 
    respond_to :html 



    def index 
     @searcher = build_searcher(params) 
     @products = @searcher.retrieve_products 
     @taxonomies = Spree::Taxonomy.includes(root: :children) 


     #Addition from Spree Fancy 
     featured = Spree::Taxon.where(:name => 'Featured').first 
     @featured_products = featured.products.active if featured 
    end 
    end 
end 

내 제품 컨트롤러 : 여기

<div class="col-md-3"> 
<li class="columns four" data-hook="featured_products_list_item"> 
<div class="product-image"> 
    <%= link_to product_image(product), product%> 
</div> 
<%= link_to truncate(product.name, :length => 50), product, :class => 'product-name', :title => product.name %> 

<span><%= product.display_price %></span> 
</li> 
</div> 

내 집 컨트롤러 : 여기

여기
<div class="container"> 
    <% if @featured_products.any? %> 
    <div id="featured-products" class="row"> 
     <h3><center>Featured Products</center></h3> 
     <hr> 
     <ul class="carousel"> 
     <% @featured_products.each do |product| %> 
      <%= render 'product', :product => product %> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

이 부분 제품 내 index.html.erb입니다 :

module Spree 
    class ProductsController < Spree::StoreController 
    before_filter :load_product, :only => :show 
    before_filter :load_taxon, :only => :index 

    rescue_from ActiveRecord::RecordNotFound, :with => :render_404 
    helper 'spree/taxons' 

    respond_to :html 

    def index 
     @searcher = build_searcher(params) 
     @products = @searcher.retrieve_products 
     @taxonomies = Spree::Taxonomy.includes(root: :children) 
    end 

    def show 
     return unless @product 

     @variants = @product.variants_including_master.active(current_currency).includes([:option_values, :images]) 
     @product_properties = @product.product_properties.includes(:property) 
     @taxon = Spree::Taxon.find(params[:taxon_id]) if params[:taxon_id] 
    end 

    private 
     def accurate_title 
     @product ? @product.name : super 
     end 

     def load_product 
     if try_spree_current_user.try(:has_spree_role?, "admin") 
      @products = Product.with_deleted 
     else 
      @products = Product.active(current_currency) 
     end 
     @product = @products.friendly.find(params[:id]) 
     end 

     def load_taxon 
     @taxon = Spree::Taxon.find(params[:taxon]) if params[:taxon].present? 
     end 
    end 
end 

내가 잘못하고있는 아이디어가 있습니까?! Spree Fancy에서 사용 된 약간의 코드를 복사하여이 "추천 제품"섹션을 만들었습니다. 그러나, 내 물건을 두 번 나열하는 것 같습니다.

감사합니다 모두에게/누구!

답변