Can I override the redirect after sign-up for unconfirmed user?

657 views
Skip to first unread message

Wolfram Arnold, RubyFocus

unread,
Jul 15, 2010, 4:39:35 PM7/15/10
to Devise, dsh...@papercheck.com, k...@cissor.com
Hi,

We're using Confirmable, and after sign-up, the new (and unconfirmed)
user is getting redirected to the sign-in page with a flash notice to
confirm their account. We'd like to override the URL the user is
redirected to. This is on Rails 2.3.8.

We weren't able to find out how to do this. I traced it to the
sign_in_and_redirect method which calls Warden's sign_in method. That
sign-in method runs through callback hooks and the Activatable
callback winds up throwing a warden exception. I can't find where
that exception is caught and processed.

I think at this point the application is in Rack land and I don't see
anything in the Rails logs about the redirect. Nor can I test it well
with Cucumber. We get different redirects depending on whether we run
the server or run cucumber. I'm guessing that Cucumber (not using
Capybara) handled Rack differently.

Thoughts?

Thanks,

Wolf

Carlos Antonio da Silva

unread,
Jul 15, 2010, 5:06:51 PM7/15/10
to plataforma...@googlegroups.com
When something is thrown in Warden, Devise FailureApp is called to handle the message and redirect the user.
You can take a look on it, there are some threads about failure app and also information in the Wiki.
--
At.
Carlos A. da Silva

José Valim

unread,
Jul 15, 2010, 6:28:09 PM7/15/10
to plataforma...@googlegroups.com
Yes, Carlos is correct. Is actually quite hard to achieve what you want, you would need to inherit from Devise::FailureApp and change the URL it redirects to if the reason is unconfirmed user.
--
José Valim

Director of Engineering - Plataforma Tecnologia
Know more about us: http://plataformatec.com.br/en/

Wolfram Arnold, RubyFocus

unread,
Jul 15, 2010, 7:50:56 PM7/15/10
to Devise
Thanks to both Carlos and José.

I hadn't realized that in the exception case a whole new Rack app is
run--FailureApp. It all makes more sense now.

I looked at FailureApp and found that there is a default_url that it
redirects to if no scope is set. In our case it would be good enough
to override the default_url that it redirects to for all failure
cases. I saw that :default_url is a cattr_accessor, and I tried
overriding it in the Rails initializater for devise (devise.rb), but
that didn't seem to take effect.

On second look, the default_url is only used if the warden scope is
not set, but I think it's always set. I don't know if I can override
the warden options in env, or if really the only option is to inherit
from FailureApp as José says. If I inherit from FailureApp, I presume
I would set the new FailureApp in the configuration?

Thanks,

Wolf

Carlos Antonio da Silva

unread,
Jul 15, 2010, 8:16:57 PM7/15/10
to plataforma...@googlegroups.com
Yes, you'll need to set your failure app in devise initializer.
There is an example on how to to it in the wiki: 

Wolfram Arnold, RubyFocus

unread,
Jul 15, 2010, 9:08:10 PM7/15/10
to Devise
Thanks for the pointer to the wiki; I had seen that before but didn't
think it applied. Now I do. Thanks for your patience. Devise is a
great tool!

Wolf

On Jul 15, 5:16 pm, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> Yes, you'll need to set your failure app in devise initializer.
> There is an example on how to to it in the wiki:http://wiki.github.com/plataformatec/devise/howto-redirect-to-a-speci...
Reply all
Reply to author
Forward
0 new messages