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

时间:2016-07-01 22:30:46

标签: ruby-on-rails ruby model-view-controller routes link-to

如果用户点击代表challenges的图标,如何在主页上仅列出具有相同categorization的{​​{1}}?

enter image description here

查看

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

1 个答案:

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