Search code examples
ruby-on-railsdevisereset-password

Devise recoverable - creating a view for the user to send the reset password email


First post here! I am attempting to extend devise to use the recoverable option so that a user can send themselves an email with a password reset link in it.

I have the recoverable option set in my user.rb model:

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, :omniauth_providers => [:facebook]

I have added the following to the login form at views/devise/sessions/new.html:

<div class="form-group">
          <%= f.label :password_confirmation, class: "sr-only" %>
          <%= f.password_field :password_confirmation, placeholder: "Confirm Password", autocomplete: "off", class: "form-control"  %>
        </div>

However, when I click that link it takes me to http://localhost:3000/users/password/new, the page is blank (it pulls in the header and footer but no content) which to me suggest that I have that page already but can't locate it in my codebase, is this correct? I assume if I didn't have that page already it would throw a 404 error?

So the things I'm looking to understand are:

a) How do I create a new view and display it at that URL b) I need to add the email form and submit button, but what does this code look like?

Any help would be much appreciated, I know this is probably something quite basic I just can't seem to wrap my head around it!

Rails version 4.2.0
Ruby version 2.0.0

Thanks in advance.

Dan


Solution

  • In order to have and modify devise views you should generate them. So run this command in your projet directory: rails generate devise:views This will generate views in "prject_path/app/views/devise" which will be used in for all devise models. If you have more than one devise model you should use: rails generate devise:views model_name This will generate "prject_path/app/views/model_name" and this will be used only for one model. Reset password view is "prject_path/app/views/devise/passwords/edit.html.erb" and it have needed functionality, but in order to send mails you should to setup your application malier. I recommend you this: Getting Devise 1.3.4 to send emails with Gmail in development