Forum: Ruby on Rails redirect :back unless members controller?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
csn (Guest)
on 2006-02-02 05:28
I'd like to do something like this when members log out:

redirect_to :back unless :back.controller=='members' (then redirect to
main site index)

Anybody know a way?

Russ McBride (Guest)
on 2006-02-02 06:38
(Received via mailing list)

I think someone told me to rtfm when I asked this question about a
month ago.  I did read "it", and hunted around but it wasn't at all
obvious to me, and I was really glad when someone helped out, so
hopefully I can recycle the help a bit.

If I understand your problem correctly, the trick is in getting the
action that was last called.  This can be found in the params hash.
It's useful to throw a  <%= debug params %> in a page and take a look
at it.  It got :action and :controller so in a page you can do this:

<% if @params[:action] == "members_action" %> some stuff
<% else %> some other stuff
<% end %>

or something similar in an .rb file without the brackets.

This code will dump out your session info and params info in a page.

<% if ENV['RAILS_ENV'] == 'development' %>
<%= debug session %>
<%= debug params %>
<% end %>

got it from here:

Hopefully, some of that helps.
This topic is locked and can not be replied to.