Class: Cats::Core::RoutesController

Inherits:
ApplicationController show all
Includes:
Common
Defined in:
app/controllers/cats/core/routes_controller.rb

Instance Method Summary collapse

Methods included from Common

#create, #show, #update

Methods inherited from ApplicationController

#authenticate, #current_user, #skip_bullet

Instance Method Details

#bulk_createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/cats/core/routes_controller.rb', line 17

def bulk_create
  p = bulk_create_params
  source = Location.find(p[:source_id])
  destinations = Location.where(id: p[:destination_ids]).pluck(:id, :name)
  data = p[:destination_ids].each_with_object([]) do |id, res|
    destination_name = destinations.find { |d| d[0] == id }[1]
    res << {
      region_id: p[:region_id],
      source_id: p[:source_id],
      destination_id: id,
      name: "#{source.name} - #{destination_name}"
    }
  end

  result = Route.insert_all!(data, record_timestamps: true)
  routes = Route.includes(:region).where(id: result.rows.flatten)
  render json: {success: true, data: serialize(routes)}
end

#filterObject



12
13
14
15
# File 'app/controllers/cats/core/routes_controller.rb', line 12

def filter
  query = Route.includes(:region).ransack(params[:q])
  render json: {success: true, data: serialize(query.result)}
end

#indexObject



6
7
8
9
10
# File 'app/controllers/cats/core/routes_controller.rb', line 6

def index
  super do
    Route.all.includes(:region)
  end
end