diff options
| author | Xinhui | 2017-03-03 15:01:28 +0100 |
|---|---|---|
| committer | Xinhui | 2017-03-03 15:01:50 +0100 |
| commit | a7bb0806b80715a54ab5b51438b3f96088d0a328 (patch) | |
| tree | f4cda2d8b9e5f21b4857bebf60246c80a3e03a77 | |
| parent | 930f233dc85b17fb877fc59f362534110dc906d1 (diff) | |
| download | chouette-core-a7bb0806b80715a54ab5b51438b3f96088d0a328.tar.bz2 | |
Refactoring AutocompleteTimeTablesController#index search
| -rw-r--r-- | app/controllers/autocomplete_time_tables_controller.rb | 17 | ||||
| -rw-r--r-- | config/routes.rb | 2 |
2 files changed, 6 insertions, 13 deletions
diff --git a/app/controllers/autocomplete_time_tables_controller.rb b/app/controllers/autocomplete_time_tables_controller.rb index ee0f8a0cb..641b6ebf5 100644 --- a/app/controllers/autocomplete_time_tables_controller.rb +++ b/app/controllers/autocomplete_time_tables_controller.rb @@ -1,6 +1,5 @@ class AutocompleteTimeTablesController < InheritedResources::Base respond_to :json, :only => [:index] - before_action :switch_referential def switch_referential @@ -14,20 +13,14 @@ class AutocompleteTimeTablesController < InheritedResources::Base protected def select_time_tables + scope = referential.time_tables if params[:route_id] - referential.time_tables.joins( vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})") - else - referential.time_tables - end - end - - def referential_time_tables - @referential_time_tables ||= select_time_tables + scope = scope.joins(vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})") + end + scope end def collection - comment_selection = referential_time_tables.select{ |p| p.comment =~ /#{params[:q]}/i } - tag_selection = referential_time_tables.tagged_with( params[:q], :wild => true) - @time_tables = (comment_selection + tag_selection).uniq + @time_tables = select_time_tables.search(params[:q]).result end end diff --git a/config/routes.rb b/config/routes.rb index c09ee27ce..58d8c5d5c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,7 +74,7 @@ ChouetteIhm::Application.routes.draw do resources :autocomplete_stop_areas, only: [:show, :index] do get 'around', on: :member end - resources :autocomplete_time_tables + resources :autocomplete_time_tables, only: [:index] resources :autocomplete_route_sections resources :autocomplete_timebands resources :group_of_lines, controller: "referential_group_of_lines" do |
