Forum: Ruby on Rails Getting the name of the calling controller

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.
David M. (Guest)
on 2006-02-09 07:01
(Received via mailing list)
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.
Kent S. (Guest)
on 2006-02-09 07:27
(Received via mailing list)
Try ActionController::Base#controller_name

Kent.
Bob S. (Guest)
on 2006-02-09 07:36
(Received via mailing list)
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 S.
http://www.railtie.net/
David M. (Guest)
on 2006-02-09 07:55
(Received via mailing list)
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.
Alex Y. (Guest)
on 2006-02-09 11:31
(Received via mailing list)
David M. 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.
Franck (Guest)
on 2006-02-10 10:19
(Received via mailing list)
params[:controller] ??
Alex Y. (Guest)
on 2006-02-10 10:35
(Received via mailing list)
Franck wrote:
> params[:controller] ??
Um...  Yes?

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