if params[:category].blank?
@items = Item.all.order("created_at DESC")
else
@category_id = Category.find_by(name: params[:category]).id
@items = Item.where(category_id: @category_id).order("created_at DESC")
end
if params[:foodtype].blank?
@items = Item.all.order("created_at DESC")
else
@food_type_id = FoodType.find_by(name: params[:foodtype]).id
@items = Item.where(food_type_id: @food_type_id).order("created_at DESC")
end
if params[:ethniccuisine].blank?
@items = Item.all.order("created_at DESC")
else
@ethnic_cuisine_id = EthnicCuisine.find_by(name: params[:ethniccuisine]).id
@items = Item.where(ethnic_cuisine_id: @ethnic_cuisine_id).order("created_at DESC")
end
目前,只有EthinicCuisine中的商品是可排序的。如何显示属于任何类别的项目?