【发布时间】:2016-07-01 22:30:45
【问题描述】:
如果用户单击代表categorization 的图标,如何在主页上仅列出具有相同categorization 的challenges?
查看
<%= 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') }
【问题讨论】:
-
你得到了什么错误?
-
TypeError (nil is not a symbol):@potashin 用于控制器中的线路
标签: ruby-on-rails ruby model-view-controller routes link-to