如果用户点击代表challenges
的图标,如何在主页上仅列出具有相同categorization
的{{1}}?
查看
categorization
如果用户点击上面的<%= 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
的挑战。
的routes.rb
categorization
pages_controller.rb
get ":categorization", to: "pages#home", as: 'categorization'
challenge.rb
def home
@challenges = current_user.challenges.send(params[:categorization]).order("deadline ASC")
end
答案 0 :(得分:0)
我需要它是单数的:
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') }