Redirect Issue


#1

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.


#2

Use a before_filter for the edit action? See,
http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html

On Jul 25, 3:34 pm, Matthew L. removed_email_address@domain.invalid


#3

On 7/25/07, Matthew L. removed_email_address@domain.invalid 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.


#4

Great thanks alot!