diff options
| author | vlatka pavisic | 2016-11-17 17:33:26 +0100 | 
|---|---|---|
| committer | vlatka pavisic | 2016-11-17 17:33:32 +0100 | 
| commit | 7efedaa1147b43a8a85e0c5eed6b512628c011db (patch) | |
| tree | bc1584787f8c3f6c8a0d2f3187bdd71ba4da7fc4 | |
| parent | e38d353ceb9e95aca546c962e99fb82bea7be274 (diff) | |
| download | chouette-core-7efedaa1147b43a8a85e0c5eed6b512628c011db.tar.bz2 | |
Refs #1939 : Create Line by_text scope
| -rw-r--r-- | app/controllers/lines_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/referential_lines_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/line.rb | 3 | 
3 files changed, 5 insertions, 2 deletions
| diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index a93084012..bd1550a00 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -69,7 +69,7 @@ class LinesController < BreadcrumbController    end    def filtered_lines -    line_referential.lines.select{ |t| [t.name, t.published_name].find { |e| /#{params[:q]}/i =~ e }  } +    line_referential.lines.by_text(params[:q])    end    def collection diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index 165b4c262..05f80f718 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -63,7 +63,7 @@ class ReferentialLinesController < ChouetteController    end    def filtered_lines -    referential.lines.select{ |t| [t.name, t.published_name].find { |e| /#{params[:q]}/i =~ e }  } +    referential.lines.by_text(params[:q])    end    def collection diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index c3a867caa..76a421b4c 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -32,6 +32,9 @@ class Chouette::Line < Chouette::ActiveRecord    validates_presence_of :name +  scope :by_text, ->(text) { where('lower(name) LIKE :t or lower(published_name) LIKE :t or lower(objectid) LIKE :t or lower(comment) LIKE :t or lower(number) LIKE :t', +    t: "%#{text.downcase}%") } +    def self.nullable_attributes      [:published_name, :number, :comment, :url, :color, :text_color, :stable_id]    end | 
