Function could determine the caller action?

Is it possible to determine which action call the function ?

In example, func_test in ApplicationController could determine which
action from SiteController is calling her ?

in class ApplicationController I have

def func_test
if ( calling from index )
return “1” end

if ( calling from contact )
return “2” end
end

and in class SiteController

def index
@var = func_test
end

def contact
@var = func_test
end

Thanks

if action_name == ‘index’


Kent

I can’t check this at the moment, but I think Ruby supports this:

def test
caller
end

test # should give the object that called test

http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/function.html#caller

Although, for your case, action_name is probably more suitable :slight_smile:

-Jonny.

No. action_name is not Ruby or ROR functionnality

Have you tried it?

Kent

Yes just test it, return an error. I need to pass an arguement ?

action_name is an attribute of class AtionController::Base. It does
not require an argument. Can you post the exception stack trace?


Kent

class TestController
def test
render :text => action_name
end
end

Works fine for me.

-Jonny.