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?
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') }
quelles erreurs obtenez-vous? – potashin
'TypeError (nul n'est pas un symbole):' @potashin pour la ligne dans le contrôleur –