Search code examples
padrino

Find controller name inside view in Padrino


How can I access the controller name inside a partial or a view thats rendered by the controller.

I want to create a dynamic template that changes depending on the controller rendering it, whats the best way to do it? I would prefer to access the controller inside the view rather than setting a new variable.


Solution

  • There are two methods to detect the entry point in Padrino: request.controller and request.action.

    controller :foo do
      get :bar do
        [request.controller, request.action].inspect
      end
    end
    
    => ["foo", :bar]