ruby-on-railscapability

What modules to include to make a selectable controller in Rails?


I want to implement an object-capabilities system in Rails and that means having a single route dispatching on dozens of different facet objects:

resources :facets, param: :swissnumber

Implmenting this via code in the routing as suggested in Rails Routes - Select controller dynamically seems highly impractical, so I'd prefer to use STI instead in the Facet model.

I'd have a barebones controller that would just dispatch actions to the facet:

def show
  Facet.find(params[:swissnumber]).show(request,params)
end

So in methods of the Facet model, I want to be able to call methods typical of controllers, like head or render. What modules can I expect to need?

For the moment, I'm chasing what modules I should include, starting with ActionController::Head and ActionController::Rendering but they're not enough and I was wondering if there's an umbrella module.

Or maybe my Facet should extend ActionController::API or ::Base and include modules from ActiveRecord? (I'm in a multiple inheritance scenario…)


Solution

  • I realized I was looking to replicate the syntax of a typical controller source code, but it's just methods on an implicit object, so the simple solution was to pass the controller to the facet, where I do controller.render or controller.request and so on…