From 1b48882c0e91354ae4eadd3ab02d80d8dd0ef085 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Feb 2015 23:46:50 +0100 Subject: [PATCH] Refactor orders index --- app/controllers/orders_controller.rb | 1 + app/models/supplier.rb | 1 + app/views/orders/index.html.haml | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 91107e6f..a1e69ee0 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -22,6 +22,7 @@ class OrdersController < ApplicationController else sort = "ends DESC" end + @suppliers = Supplier.having_articles.order('suppliers.name') @orders = Order.closed.includes(:supplier).reorder(sort).page(params[:page]).per(@per_page) end diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 6332aad7..a8f77781 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -19,6 +19,7 @@ class Supplier < ActiveRecord::Base validate :uniqueness_of_name scope :undeleted, -> { where(deleted_at: nil) } + scope :having_articles, -> { where(id: Article.undeleted.select(:supplier_id).distinct) } # sync all articles with the external database # returns an array with articles(and prices), which should be updated (to use in a form) diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 65bf11a3..be6d7f1d 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -6,7 +6,7 @@ = t '.new_order' %span.caret %ul.dropdown-menu - - Supplier.where(id: Article.undeleted.select(:supplier_id).distinct).order('suppliers.name ASC').each do |supplier| + - for supplier in @suppliers %li= link_to supplier.name, new_order_path(supplier_id: supplier.id), tabindex: -1 .well