From bfa538e644405861cbec5558d3ee4a23d8ab06e3 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 30 Nov 2012 23:15:37 +0600 Subject: [PATCH] [refs #732] small refactoring --- app/controllers/api/v1/maintainers_controller.rb | 10 ++++------ app/controllers/platforms/maintainers_controller.rb | 9 ++++----- app/models/build_list/package.rb | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/maintainers_controller.rb b/app/controllers/api/v1/maintainers_controller.rb index a85203e4b..cda1761f1 100644 --- a/app/controllers/api/v1/maintainers_controller.rb +++ b/app/controllers/api/v1/maintainers_controller.rb @@ -3,11 +3,9 @@ class Api::V1::MaintainersController < Api::V1::BaseController load_and_authorize_resource :platform def index - @maintainers = BuildList::Package.actual.by_platform(@platform) - .includes(:project) - if name = params[:filter].try(:[], :package_name) - @maintainers = @maintainers.like_name(name) - end - @maintainers = @maintainers.paginate(paginate_params) + @maintainers = BuildList::Package.includes(:project) + .actual.by_platform(@platform) + .like_name(params[:filter].try(:[], :package_name)) + .paginate(paginate_params) end end diff --git a/app/controllers/platforms/maintainers_controller.rb b/app/controllers/platforms/maintainers_controller.rb index 10e200aa3..9abd417de 100644 --- a/app/controllers/platforms/maintainers_controller.rb +++ b/app/controllers/platforms/maintainers_controller.rb @@ -5,10 +5,9 @@ class Platforms::MaintainersController < ApplicationController load_and_authorize_resource :platform def index - @maintainers = BuildList::Package.actual.by_platform(@platform) - .includes(:project) - @maintainers = @maintainers.like_name(params[:q]) if params[:q].present? - @maintainers = @maintainers.paginate(:page => params[:page]) + @maintainers = BuildList::Package.includes(:project) + .actual.by_platform(@platform) + .like_name(params[:q]) + .paginate(:page => params[:page]) end - end diff --git a/app/models/build_list/package.rb b/app/models/build_list/package.rb index 108f9ea4e..891fe239b 100644 --- a/app/models/build_list/package.rb +++ b/app/models/build_list/package.rb @@ -19,7 +19,7 @@ class BuildList::Package < ActiveRecord::Base scope :by_platform, lambda {|platform| where(:platform_id => platform) } scope :by_name, lambda {|name| where(:name => name) } scope :by_package_type, lambda {|type| where(:package_type => type) } - scope :like_name, lambda {|name| where('name ILIKE ?', "%#{name}%")} + scope :like_name, lambda {|name| where('name ILIKE ?', "%#{name}%") if name.present?} def assignee project.maintainer