2016-07-01 26 views
-1

categorizationを表すアイコンをユーザーがクリックすると、challengesと同じcategorizationのホームページのみに一覧表示するにはどうすればよいですか?同じ属性の同じページにオブジェクトを表示するにはどうすればよいですか?

enter image description here

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

ユーザは、そのそれぞれのcategorizationとすべき唯一のリストの課題を上記link_toをクリックします。

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

関連する問題