I know I''ve seen this before, but I can''t find it and Google hasn''t been a help...>From within a controller method, how can I find the name of therequesting controller? For example, if I''m in controller C1 and I do a redirect_to :controller=> ''foo'', :action => ''bar'', how can I find the name of the requesting controller (C1) from within method ''bar''? I thought it was request.controller, but that doesn''t seem to work. Regards Dave M.
Try ActionController::Base#controller_name Kent. On 2/9/06, David Mitchell <monch1962@gmail.com> wrote:> I know I''ve seen this before, but I can''t find it and Google hasn''t > been a help... > > >From within a controller method, how can I find the name of the > requesting controller? For example, if I''m in controller C1 and I do > a > redirect_to :controller=> ''foo'', :action => ''bar'', > how can I find the name of the requesting controller (C1) from within > method ''bar''? > > I thought it was request.controller, but that doesn''t seem to work. > > Regards > > Dave M. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Why not just pass it on query string. Redirect_to is a full 302 browser redirect, so it shouldn''t have any knowledge (outside of HTTP_REFERER, which isn''t dependable) of the previous controller. However, as with everything else in life, I could be wrong. Bob Silva http://www.railtie.net/> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of David Mitchell > Sent: Wednesday, February 08, 2006 9:01 PM > To: rails@lists.rubyonrails.org > Subject: [Rails] Getting the name of the calling controller > > I know I''ve seen this before, but I can''t find it and Google hasn''t > been a help... > > >From within a controller method, how can I find the name of the > requesting controller? For example, if I''m in controller C1 and I do > a > redirect_to :controller=> ''foo'', :action => ''bar'', > how can I find the name of the requesting controller (C1) from within > method ''bar''? > > I thought it was request.controller, but that doesn''t seem to work. > > Regards > > Dave M. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
David Mitchell
2006-Feb-09 05:55 UTC
[Rails] Re: Getting the name of the calling controller
Hmm, doesn''t seem to exist after all. Best I can come up with is request.path.split(''/'')[1] which isn''t exactly intuitive and may not work in some environments... Regards Dave M. On 09/02/06, David Mitchell <monch1962@gmail.com> wrote:> I know I''ve seen this before, but I can''t find it and Google hasn''t > been a help... > > From within a controller method, how can I find the name of the > requesting controller? For example, if I''m in controller C1 and I do > a > redirect_to :controller=> ''foo'', :action => ''bar'', > how can I find the name of the requesting controller (C1) from within > method ''bar''? > > I thought it was request.controller, but that doesn''t seem to work. > > Regards > > Dave M. >
David Mitchell wrote:> Hmm, doesn''t seem to exist after all. > > Best I can come up with is > request.path.split(''/'')[1] > which isn''t exactly intuitive and may not work in some environments...Without specific support, I''d put this in the application controller: after_filter {session[:last_params] = params} That way you can get the last controller name as session[:last_params][:controller] from anywhere. -- Alex
params[:controller] ?? On 2/9/06, Alex Young <alex@blackkettle.org> wrote:> > David Mitchell wrote: > > Hmm, doesn''t seem to exist after all. > > > > Best I can come up with is > > request.path.split(''/'')[1] > > which isn''t exactly intuitive and may not work in some environments... > Without specific support, I''d put this in the application controller: > > after_filter {session[:last_params] = params} > > That way you can get the last controller name as > session[:last_params][:controller] from anywhere. > > -- > Alex > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060210/1731ac9b/attachment.html
Franck wrote:> params[:controller] ??Um... Yes? -- Alex> > On 2/9/06, *Alex Young* <alex@blackkettle.org > <mailto:alex@blackkettle.org>> wrote: > > David Mitchell wrote: > > Hmm, doesn''t seem to exist after all. > > > > Best I can come up with is > > request.path.split(''/'')[1] > > which isn''t exactly intuitive and may not work in some > environments... > Without specific support, I''d put this in the application controller: > > after_filter {session[:last_params] = params} > > That way you can get the last controller name as > session[:last_params][:controller] from anywhere. > > -- > Alex > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org <mailto: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