Recourse

Retrievable tables

A table whose rows come from somewhere else — a marketplace’s orders — offers to fetch them again:

recourses :stores do
  recourses :orders, only: :index, retrievable: true
end

That draws POST /stores/5/orders/retrieval and a Retrieve button beside the breadcrumb of the table. Where the rows come from is the host’s to know, so the host writes the controller, a RecoursesController like every other:

class Stores::Orders::RetrievalsController < RecoursesController
  def create
    store = Store.find params.expect(:store_id)
    store.import_orders
    redirect_to store_orders_path(store), status: :see_other
  end
end

A page says when there is nothing to fetch from by narrowing recourse_retrievable? on the listing controller, which takes the button away and leaves the route:

class Stores::OrdersController < RecoursesController
private

  def recourse_retrievable? = @store.connected?
end