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.

Try ActionController::Base#controller_name

Kent.

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/

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.

params[:controller] ??

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 wrote:

params[:controller] ??
Um… Yes?


Alex