I have a list of categories. When you click on a category lets say Computers it should only show a tag cloud of the items in that category in this case Computers. Tags from the Mobile Phone category should not be showing.
Currently my tag cloud shows all tags across all categories.
Im using the Acts_as_tagable_gem http://ift.tt/Pchlg6
How would someone go about showing only the tags inside that category?
Here is my view. Please refer to tag_cloud
<p id="notice"><%= notice %></p>
<div class = "col-md-3">
<h1>
<strong><%= @category.name %></strong>
</h1>
</div>
<div class = "col-md-9">
<div id="tag_cloud">
<% tag_cloud(@tags, %w[s m l]) do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.name, id: @category.id), class: css_class %>
<% end %>
</div>
</div>
<div class = "col-md-12">
<div class="line-separator"></div>
</div>
<div class = "col-md-12">
<div id="items" class="transitions-enabled">
<% @items.each do |item| %>
<div class="box panel panel-default">
<div class="itemlisttitle"><%= item.title %></div>
<%= link_to image_tag(item.image.url (:medium)), item %>
<div class ="panel-body">
<div class = "itemlistprice">$<%= item.price %></div>
<div class = "itemlistretailer"><%= image_tag item.user.avatar(:thumb) %> Retailer: <%= link_to item.user.username, item.user %></div>
</div>
</div>
<% end %>
</div>
</div>
Routes Please refer to the last line
Rails.application.routes.draw do
resources :categories
get 'password_resets/new'
get 'password_resets/edit'
get 'sessions/new'
resources :users
get 'user_items' => 'users#show_user_items'
root 'items#home'
get 'signup' => 'users#new'
get 'show' => 'users#show'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :account_activations, only: [:edit]
resources :password_resets, only: [:new, :create, :edit, :update]
resources :items
get 'items_new' => 'items#new'
get 'tags/:tag', to: 'categories#show', as: :tag
Category Controller Show Action.
def show
@tags = Item.tag_counts_on(:tags)
if params[:tag]
@items = Item.tagged_with(params[:tag])
else
@items = Item.where(category_id: @category.id).order("created_at DESC")
end
end
Aucun commentaire:
Enregistrer un commentaire