From 688a3d8f31ba4771f1fca9a2449f3b5481a515b2 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 12 Apr 2017 10:28:22 +0200 Subject: [PATCH] Define .brouillon as a scope and remove archived=false filter --- app/controllers/users/dossiers_controller.rb | 2 +- app/models/dossier.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 313037fed..73e856c00 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -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' diff --git a/app/models/dossier.rb b/app/models/dossier.rb index f22deacda..80d067cef 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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