2016-04-21 45 views
1

我正在自定義一個大禮包應用程序,並且卡住了試圖根據我是哪個分類單位來更改我的視圖。Spree:更改視圖,取決於分類羣

我有兩個「主要」分類,它們是:「註冊表」和「類別」。這些分類學家有不同的觀點。

分類羣#顯示:

def show 
    @taxon = Taxon.friendly.find(params[:id]) 
    return unless @taxon 
    @searcher = build_searcher(params.merge(include_images: true)) 
    @products = @searcher.retrieve_products 
    @taxonomies = Spree::Taxonomy.includes(root: :children) 
end 

參考文獻:

Render a rails partial based on the id of an action

Rendering rails partial with dynamic variables

回答

0

我沒有完全理解你的問題,但仍,你有兩個主要的分類羣 '一' &'b',你想改變視圖

如果僅僅隨時隨地查看喜歡的樣式表,你可以使用的ActionView

<%if current_page?('/t/registries')%> 
<!--something--> 
<%end%> 

下,如果你想通過控制器

def show 
    @taxon = Taxon.friendly.find(params[:id]) 
    if @taxon.name == "registries" 
    redirect_to 'name_of_custom_action_for_the_desired_view' 
    end 
    #and you can fetch products and taxonomies in the view 
end 

希望得到的答案是有幫助

改變整個模板
相關問題