Search code examples
rubyramaze

Get current controller and action name in Ramaze


Is there a way to get the currently executing controller and action name in Ramaze?

require 'ramaze'

class FooController < Ramaze::Controller
  def bar
    "#{controller}.#{action}" #how to get this to work?
  end
end

PS: I know self.class.name would give you the class name/controller name but was wondering if this captured somewhere else in the Ramaze API. Also __method__ should give the action name but I don't want to create variables when I pass this info to templates.


Solution

  • You can get them with :

    controller = action.node
    method = action.method
    

    See https://github.com/Ramaze/ramaze/wiki/Knowing-which-controller-or-method-triggered-view-layout-rendering