aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/autocomplete_lines_controller.rb
blob: 6f5009390c7ccecd6aee0ad9885d705563f90c42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class AutocompleteLinesController < ChouetteController
  include ReferentialSupport

  respond_to :json, only: :index

  protected

  def collection
    @lines = referential.line_referential.lines

    @lines = @lines
      .joins(:company)
      .where('
        lines.number LIKE ?
        OR lines.name LIKE ?
        OR companies.name ILIKE ?',
        *Array.new(3, "%#{params[:q]}%")
      )
      .search(params[:q])
      .result
      .paginate(page: params[:page])
  end
end