0
我正在創建一個市場應用程序,賣家可以列出要銷售的物品。我想創建一個類別下拉菜單,以便客戶可以選擇一個類別進行購物。Rails 4堆棧級別太深Error
在我的列表模型中,我有一個'category'字段。當用戶選擇一個類別時,我希望該視圖能夠過濾來自該類別的列表。
在我的routes.rb:
get '/listings/c/:category' => 'listings#category', as: 'category'
要創建類別菜單 - 在我index.html.erb:
<%= Listing.uniq.pluck(:category).each do |category| %>
<%= link_to category, category_path(category: category) %>
<% end %>
在我的列表控制器:
def category
@category = category
@listings = Listing.not_expired.where(:category => @category)
end
category.html.erb:
<% @listings.each do |listing| %>
#some html
<% end %>
顯示主頁類別菜單。路線已創建。但是當我點擊這個類別時,諸如listing/c/necklaces這樣的URL會給我帶來太深的錯誤。