From f372eda831e91da367007f3e0aef725c6a67c574 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 26 Feb 2018 14:45:58 +0100 Subject: AutocompleteLinesController: Move filter SQL string inside query Get rid of the heredoc to allow us to put the string inside the argument to the function directly and thus make the query more readable by putting it in context. Refs #5889 --- app/controllers/autocomplete_lines_controller.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/controllers/autocomplete_lines_controller.rb b/app/controllers/autocomplete_lines_controller.rb index 0202ea054..6f5009390 100644 --- a/app/controllers/autocomplete_lines_controller.rb +++ b/app/controllers/autocomplete_lines_controller.rb @@ -8,15 +8,12 @@ class AutocompleteLinesController < ChouetteController def collection @lines = referential.line_referential.lines - filter = <<~SQL - lines.number LIKE ? - OR lines.name LIKE ? - OR companies.name ILIKE ? - SQL @lines = @lines .joins(:company) - .where( - filter, + .where(' + lines.number LIKE ? + OR lines.name LIKE ? + OR companies.name ILIKE ?', *Array.new(3, "%#{params[:q]}%") ) .search(params[:q]) -- cgit v1.2.3