Loomio
Wed 19 May 2021 8:04PM

Where is the index route for API::EventsController?

ELP Edward L Platt Public Seen by 61

I am trying to understand how comments are filtered and sorted in the code. According to server output, /api/v1/events gets routed to API::EventsController#index, but I don't see that index method defined anywhere. Where is it defined?

RG

Robert Guthrie Mon 24 May 2021 12:26AM

Hi @Edward L Platt, the EventsController#index method is not defined, so it inherits behaviour from the snorlax base definition, which looks like this:

  def index
    instantiate_collection
    respond_with_collection
  end

and instantiate collection looks like this, which is where you can start to see it call methods from events controller.

  def instantiate_collection
    self.collection = accessible_records
    self.collection = yield collection if block_given?
    self.collection = timeframe_collection collection
    self.collection_count = collection.count
    self.collection = page_collection collection
    self.collection = order_collection collection
  end

ELP

Edward L Platt Mon 24 May 2021 12:37AM

Ah, it's in snorlax. Gotcha, thanks!