Forum: Ruby on Rails redirect :back unless members 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.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 csn (Guest)
on 2006-02-02 04: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?

Thanks
csn
78316e522d62b1656f6e2e0cea8f90e6?d=identicon&s=25 Russ McBride (Guest)
on 2006-02-02 05:38
(Received via mailing list)
Hi,

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" %>
    ...do some stuff
<% else %>
    ...do 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:

http://wiki.rubyonrails.org/rails/pages/TipsAndTricks

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