blob: 3915bd69fd419471790fede7b2dba1ca05978345 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
class AutocompleteTimebandsController < InheritedResources::Base
respond_to :json, :only => [:index]
before_action :switch_referential
def switch_referential
Apartment::Tenant.switch!(referential.slug)
end
def referential
@referential ||= current_organisation.referentials.find params[:referential_id]
end
protected
def select_timebands
if params[:route_id]
referential.timebands.joins( vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})")
else
referential.timebands
end
end
def referential_timebands
@referential_timebands ||= select_timebands
end
def collection
@timebands = referential_timebands.select{ |p| p.fullname =~ /#{params[:q]}/i }
end
end
|