Forum: Ruby on Rails Function could determine the caller action ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
oo00oo (Guest)
on 2006-03-08 02:14
(Received via mailing list)
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
Kent S. (Guest)
on 2006-03-08 02:14
(Received via mailing list)
if action_name == 'index'

--
Kent
Jonathan V. (Guest)
on 2006-03-08 02:41
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/Manua...

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

-Jonny.
oo00oo (Guest)
on 2006-03-08 02:42
(Received via mailing list)
No. action_name is not Ruby or ROR functionnality
Kent S. (Guest)
on 2006-03-08 03:18
(Received via mailing list)
Have you tried it?

Kent
oo00oo (Guest)
on 2006-03-08 11:49
(Received via mailing list)
Yes just test it, return an error. I need to pass an arguement ?
Jonathan V. (Guest)
on 2006-03-08 13:58
class TestController
  def test
    render :text => action_name
  end
end

Works fine for me.

-Jonny.
Kent S. (Guest)
on 2006-03-08 15:29
(Received via mailing list)
action_name is an attribute of class AtionController::Base. It does
not require an argument. Can you post the exception stack trace?

--
Kent
This topic is locked and can not be replied to.