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 On 3/7/06, oo00oo <oo00oo@free.fr> wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
No. action_name is not Ruby or ROR functionnality> if action_name == ''index'' > > -- > Kent > > >
Jonathan Viney
2006-Mar-08 00:41 UTC
[Rails] Re: Function could determine the caller action ?
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 :) -Jonny. -- Posted via http://www.ruby-forum.com/.
Have you tried it? Kent On 3/7/06, oo00oo <oo00oo@free.fr> wrote:> > No. action_name is not Ruby or ROR functionnality > > > > if action_name == ''index'' > > > > -- > > Kent > > > > > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060308/2db3e040/attachment.html
Yes just test it, return an error. I need to pass an arguement ?> Have you tried it? > > Kent > > On 3/7/06, *oo00oo* <oo00oo@free.fr <mailto:oo00oo@free.fr>> wrote: > > No. action_name is not Ruby or ROR functionnality > > > > if action_name == ''index'' > > > > -- > > Kent > > > > > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Jonathan Viney
2006-Mar-08 11:58 UTC
[Rails] Re: Function could determine the caller action ?
class TestController def test render :text => action_name end end Works fine for me. -Jonny. -- Posted via http://www.ruby-forum.com/.
action_name is an attribute of class AtionController::Base. It does not require an argument. Can you post the exception stack trace? -- Kent On 3/8/06, oo00oo <oo00oo@free.fr> wrote:> Yes just test it, return an error. I need to pass an arguement ? > > Have you tried it? > > > > Kent > > > > On 3/7/06, *oo00oo* <oo00oo@free.fr <mailto:oo00oo@free.fr>> wrote: > > > > No. action_name is not Ruby or ROR functionnality > > > > > > > if action_name == ''index'' > > > > > > -- > > > Kent > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >