Define .brouillon as a scope and remove archived=false filter

This commit is contained in:
Mathieu Magnin 2017-04-12 10:28:22 +02:00
parent 21a2a5402b
commit 688a3d8f31
2 changed files with 7 additions and 7 deletions

View file

@ -16,7 +16,7 @@ class Users::DossiersController < UsersController
@dossiers_filtered = case @liste
when 'brouillon'
@user_dossiers.brouillon
@user_dossiers.brouillon.order_by_updated_at
when 'a_traiter'
@user_dossiers.en_construction
when 'en_instruction'

View file

@ -157,18 +157,18 @@ class Dossier < ActiveRecord::Base
state
end
def brouillon?
BROUILLON.include?(state)
end
def self.all_state order = 'ASC'
where(state: ALL_STATE, archived: false).order("updated_at #{order}")
end
def self.brouillon order = 'ASC'
where(state: BROUILLON, archived: false).order("updated_at #{order}")
def brouillon?
BROUILLON.include?(state)
end
scope :brouillon, -> { where(state: BROUILLON) }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
def self.nouveaux order = 'ASC'
where(state: NOUVEAUX, archived: false).order("updated_at #{order}")
end