Class: Spree::Transit::TripStopsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/transit/trip_stops_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#collection_url, #current_vendor, #edit_object_url, #page, #per_page, #required_vendor_user!, #vendors

Instance Method Details

#indexObject



5
# File 'app/controllers/spree/transit/trip_stops_controller.rb', line 5

def index; end

#load_dataObject



7
8
9
10
11
# File 'app/controllers/spree/transit/trip_stops_controller.rb', line 7

def load_data
  @product = Spree::Product.find_by(slug: params[:route_id])
  @trip = SpreeCmCommissioner::Trip.find_by(id: params[:trip_id]) if params[:trip_id]
  @trip_stops = @trip.trip_stops.sort_by(&:sequence)
end

#model_classObject



30
31
32
# File 'app/controllers/spree/transit/trip_stops_controller.rb', line 30

def model_class
  SpreeCmCommissioner::TripStop
end

#object_nameObject



26
27
28
# File 'app/controllers/spree/transit/trip_stops_controller.rb', line 26

def object_name
  'spree_cm_commissioner_trip_stop'
end

#update_sequencesObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/transit/trip_stops_controller.rb', line 13

def update_sequences
  ApplicationRecord.transaction do
    params[:positions].each do |id, index|
      SpreeCmCommissioner::TripStop.where(id: id).update(sequence: index)
    end
  end

  respond_to do |format|
    format.html { redirect_to transit_route_trip_trip_stops_path(@product, @product.trip) }
    format.js { render plain: 'Ok' }
  end
end