Ben Downey
Ben Downey

Reputation: 2665

Devise breaks when resetting password

I'm using devise and I thought everything was working, until I tred to reset a password. I get the error below. Devise can't find a template called layout/email. Why does it even want that? I was under the impression that after the form posted, devise would redirect to the user sign in page.

I suspect that devise is having trouble finding the "reset_password_instructions.html.haml" file, since it's clearly able to generate the reset token, but no email is actually sent. Based on the error message below, does that sound like the correct diagnosis?

What I do I have to do to fix this? I'm guessing I'll have to modify devise by overwriting a controller, but I'm not sure. Any suggestions?

Started POST "/users/password" for 127.0.0.1 at 2012-08-06 05:52:42 -0500
    Processing by Devise::PasswordsController#create as HTML
      Parameters: {"utf8"=>"✓", "authenticity_token"=>"kGvuZiu+iu1HAx9xf4RsISj2SM410uLRoR6RbiJcBQw=", "user"=>{"email"=>"[email protected]"}, "commit"=>"Send me reset password instructions"}
      User Load (6.0ms)  SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
      User Load (1.3ms)  SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = '5QZVFAsq2ev22gpQfe9i' LIMIT 1
       (0.1ms)  BEGIN
       (3.0ms)  UPDATE "users" SET "reset_password_token" = '5QZVFAsq2ev22gpQfe9i', "reset_password_sent_at" = '2012-08-06 10:52:42.591763', "updated_at" = '2012-08-06 10:52:42.593474' WHERE "users"."id" = 2
       (0.5ms)  COMMIT
    DEPRECATION WARNING: Passing a template handler in the template name is deprecated. You can simply remove the handler name or pass render :handlers => [:haml] instead. (called from call at /Users/bendowney/.rvm/gems/ruby-1.9.3-p194@global/gems/sass-3.1.19/lib/sass/plugin/rack.rb:54)
    DEPRECATION WARNING: Passing a template handler in the template name is deprecated. You can simply remove the handler name or pass render :handlers => [:haml] instead. (called from call at /Users/bendowney/.rvm/gems/ruby-1.9.3-p194@global/gems/sass-3.1.19/lib/sass/plugin/rack.rb:54)
    Completed 500 Internal Server Error in 113ms

    ActionView::MissingTemplate (Missing template layouts/email with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
      * "/Users/bendowney/Sites/RobotimusApp/app/views"
      * "/Users/bendowney/.rvm/gems/ruby-1.9.3-p194@RobotimusApp/gems/devise-2.1.2/app/views"
    ):
      actionpack (3.2.5) lib/action_view/path_set.rb:58:in `find'
      actionpack (3.2.5) lib/action_view/lookup_context.rb:109:in `find'
      actionpack (3.2.5) lib/action_view/renderer/abstract_renderer.rb:3:in `find_template'
      actionpack (3.2.5) lib/action_view/renderer/template_renderer.rb:79:in `resolve_layout'
      actionpack (3.2.5) lib/action_view/renderer/template_renderer.rb:86:in `resolve_layout'
      actionpack (3.2.5) lib/action_view/renderer/template_renderer.rb:69:in `block in find_layout'
      actionpack (3.2.5) lib/action_view/lookup_context.rb:228:in `with_layout_format'
#...etc

Upvotes: 1

Views: 358

Answers (1)

Thilo
Thilo

Reputation: 17735

Devise sends an email with a reset token before redirecting the user. Sending emails also requires templates and layouts. In your case, this step fails because somewhere in your code, you probably specify layout 'email' for an ActionMailer class but didn't actually create this layout template.

Try adding a file app/views/layouts/email.html.haml that at a minimum contains this:

= yield

(or <%= yield %> in an .html.erb template).

Upvotes: 2

Related Questions