如何在轨道上的ruby中对每个类别中的项目进行排序?

时间:2015-12-05 04:42:06

标签: ruby-on-rails-4

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中的商品是可排序的。如何显示属于任何类别的项目?

0 个答案:

没有答案