Confirmable: user_confirmation_url fails with path_prefix

505 views
Skip to first unread message

Bob Wentz

unread,
Jul 27, 2010, 7:49:32 PM7/27/10
to Devise
I'm using Devise 1.0.8 with Rails 2.3.5 with the Confirmable module.
I'd like to have all my URLs start with a locale prefix, so I have my
route configured as:

--------------------
map.devise_for :users, :path_prefix => '/:locale'
--------------------

I also have this in my devise.rb:

--------------------
config.default_url_options do
{ :locale => I18n.locale }
end
--------------------

And this in my application controller:

--------------------
def self.default_url_options
{ :locale => I18n.locale }
end
--------------------

However, when I try to create a new User object, the operation fails
with this error:

--------------------
ActionView::TemplateError (user_confirmation_url failed to generate
from
{:action=>"show", :confirmation_token=>"uQpzIKGcllh3GOufIK6j", :controller=>"confirmations"},
expected: {:action=>"show", :controller=>"confirmations"}, diff:
{:confirmation_token=>"uQpzIKGcllh3GOufIK6j"}) on line #5 of /Users/
robertwentz 1/.gem/ruby/1.8/gems/devise-1.0.8/app/views/devise_mailer/
confirmation_instructions.html.erb:
2:
3: <p>You can confirm your account through the link below:</p>
4:
5: <p><%= link_to 'Confirm my account',
confirmation_url(@resource, :confirmation_token =>
@resource.confirmation_token) %></p>

(eval):20:in `user_confirmation_url'
devise (1.0.8) lib/devise/controllers/url_helpers.rb:32:in `send'
devise (1.0.8) lib/devise/controllers/url_helpers.rb:32:in
`confirmation_url'
devise (1.0.8) app/views/devise_mailer/
confirmation_instructions.html.erb:5
--------------------

I noticed that in the console, so I can do this:

--------------------
app.user_confirmation_url(:locale => :en, :confirmation_token =>
"abcdef")
--------------------

But not this:

--------------------
app.user_confirmation_url(:confirmation_token => "abcdef")
--------------------

I'm guessing I'm missing something pretty simple here, but I just
can't figure out what it might be. I'll also note that if I remove
the "path_prefix" option from devise_for, and remove the
default_url_options from devise.rb, creating the object is
successful. But I no longer get the locale on the Devise controllers,
and I'd like it to be consistent throughout the site.

Apologies for formatting - I'm not sure how to do code tags here.
Thanks in advance for your help.

Mike B

unread,
Aug 11, 2010, 7:39:34 AM8/11/10
to Devise
Hi,

I solved this by adding a :locale in the view, like so:

<p><%= link_to 'Confirm my account',
confirmation_url(@resource, :confirmation_token =>
@resource.confirmation_token, :locale => I18n.locale) %></p>

HTH,
Mike

Bob Wentz

unread,
Aug 17, 2010, 9:00:55 PM8/17/10
to Devise
Thank you! That worked like a charm. I didn't realize you could
override the views, but once I figured that out, it was an easy fix.
Reply all
Reply to author
Forward
0 new messages