Forum: Ruby on Rails Redirect Issue

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.
E097e05db53608b7855d91705c5e7516?d=identicon&s=25 Matthew Lagace (turnkeytraders)
on 2007-07-25 15:34
Hello,

I have a page where anyone can edit some content on it, but they must be
logged in before doing so. Now, when the person clicks on my "edit"
action, they are automatically redirected to the login form. Then the
person logs in, but when they log in, I would like to have them
redirected to the page where they wanted to edit the content on. How can
I do that?

Thanks,
M.
2101d75ccd71c5dfb984991a7ba53b9b?d=identicon&s=25 harm (Guest)
on 2007-07-26 00:45
(Received via mailing list)
Use a before_filter for the edit action? See,
http://api.rubyonrails.org/classes/ActionControlle...

On Jul 25, 3:34 pm, Matthew Lagace <rails-mailing-l...@andreas-s.net>
813f535246722b7bf02aacc9ce818de8?d=identicon&s=25 Bob Showalter (Guest)
on 2007-07-26 00:46
(Received via mailing list)
On 7/25/07, Matthew Lagace <rails-mailing-list@andreas-s.net> wrote:
>
> Hello,
>
> I have a page where anyone can edit some content on it, but they must be
> logged in before doing so. Now, when the person clicks on my "edit"
> action, they are automatically redirected to the login form. Then the
> person logs in, but when they log in, I would like to have them
> redirected to the page where they wanted to edit the content on. How can
> I do that?

The basic idea is that before you redirect to the login page, you
stash away request.request_uri somewhere. (The session[] object is
handy, or you can put it in a hidden field in the login form).

Then, when they've successfully authenticated, grab the saved uri and
redirect to there. (You'll need some kind of default place to go in
case they don't come to the login page via a redirect.)

I suggest you look at acts_as_authenticated
(http://agilewebdevelopment.com/plugins/acts_as_authenticated). It
provides this capability built in. If nothing else, you can look at
his code and see how it's done.
E097e05db53608b7855d91705c5e7516?d=identicon&s=25 Matthew Lagace (turnkeytraders)
on 2007-07-26 01:22

Great thanks alot!
This topic is locked and can not be replied to.