如何在同一页面上列出具有相同属性的对象?

How to list objects on the same page with the same attribute?

如果用户单击代表 categorization 的图标,如何在主页上仅列出具有相同 categorizationchallenges

查看

<%= 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 %>

如果用户点击上面的 link_to,那么应该只列出相应 categorization.

的挑战

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') }

我需要它是单数的:

  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') }