2016-07-01 2 views
-1

categorization을 나타내는 아이콘을 사용자가 클릭하면 홈 페이지에 challenges과 동일한 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 %> 

enter image description here

보면 다음 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') } 
+1

어떤 오류가 발생합니까? – potashin

+0

'TypeError (nil은 기호가 아닙니다.) : 컨트롤러의 행에 대해 @potashin –

답변

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

독자적인 답변 수락을 고려하십시오. http://blog.stackoverflow.com/2009/01/accept-your-own-answers/ – SoAwesomeMan

관련 문제