aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/autocomplete_time_tables_controller.rb17
-rw-r--r--config/routes.rb2
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