Refactor orders index

This commit is contained in:
wvengen 2015-02-18 23:46:50 +01:00
parent 27fe8a4d42
commit 1b48882c0e
3 changed files with 3 additions and 1 deletions

View file

@ -22,6 +22,7 @@ class OrdersController < ApplicationController
else else
sort = "ends DESC" sort = "ends DESC"
end end
@suppliers = Supplier.having_articles.order('suppliers.name')
@orders = Order.closed.includes(:supplier).reorder(sort).page(params[:page]).per(@per_page) @orders = Order.closed.includes(:supplier).reorder(sort).page(params[:page]).per(@per_page)
end end

View file

@ -19,6 +19,7 @@ class Supplier < ActiveRecord::Base
validate :uniqueness_of_name validate :uniqueness_of_name
scope :undeleted, -> { where(deleted_at: nil) } scope :undeleted, -> { where(deleted_at: nil) }
scope :having_articles, -> { where(id: Article.undeleted.select(:supplier_id).distinct) }
# sync all articles with the external database # sync all articles with the external database
# returns an array with articles(and prices), which should be updated (to use in a form) # returns an array with articles(and prices), which should be updated (to use in a form)

View file

@ -6,7 +6,7 @@
= t '.new_order' = t '.new_order'
%span.caret %span.caret
%ul.dropdown-menu %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 %li= link_to supplier.name, new_order_path(supplier_id: supplier.id), tabindex: -1
.well .well