2016-07-01 4 views
-1

Comment lister sur la page d'accueil seulement le challenges avec le même categorization si un utilisateur clique sur l'icône représentant categorization?Comment lister des objets sur la même page avec le même attribut?

enter image description here

vue

<%= link_to categorization_path(categorization: :adventure) do %>  
    <span class="glyphicon glyphicon-picture", id="challenge-category"></span> 
<% end %> 
<%= link_to categorization_path(categorization: :health) do %>  
    <span class="glyphicon glyphicon-heart", id="challenge-category"></span> 
<% end %> 
<%= link_to categorization_path(categorization: :work) do %>  
    <span class="glyphicon glyphicon-briefcase", id="challenge-category"></span> 
<% end %> 
<%= link_to categorization_path(categorization: :buy) do %>  
    <span class="glyphicon glyphicon-shopping-cart", id="challenge-category"></span> 
<% end %> 
<%= link_to categorization_path(categorization: :wacky) do %>  
    <span class="glyphicon glyphicon-wine-glass", id="challenge-category"></span> 
<% end %> 

Si un utilisateur clique sur un link_to ci-dessus alors que devrait uniquement les défis de la liste avec cette categorization respective.

routes.rb

get ":categorization", to: "pages#home", as: 'categorization' 

pages_controller.rb

def home 
@challenges = current_user.challenges.send(params[:categorization]).order("deadline ASC") 
end 

challenge.rb

CATEGORIZATION = ['adventure', 'health', 'work', 'buy', 'wacky'] 
scope :adventure, -> { where(categorizations: 'Adventure') } 
scope :health, -> { where(categorizations: 'Health') } 
scope :work, -> { where(categorizations: 'Work') } 
scope :buy, -> { where(categorizations: 'Buy') } 
scope :wacky, -> { where(categorizations: 'Wacky') } 
+1

quelles erreurs obtenez-vous? – potashin

+0

'TypeError (nul n'est pas un symbole):' @potashin pour la ligne dans le contrôleur –

Répondre

0

je en avais besoin de être singulier:

scope :adventure, -> { where(categorization: 'adventure') } 
    scope :health, -> { where(categorization: 'health') } 
    scope :work, -> { where(categorization: 'work') } 
    scope :buy, -> { where(categorization: 'buy') } 
    scope :wacky, -> { where(categorization: 'wacky') } 
+0

Pensez à accepter votre propre réponse: http://blog.stackoverflow.com/2009/01/accept-your-own-answers/ – SoAwesomeMan