You’ll see a shitload of tutorials out there about this, but none have been written by me yet. So here comes one. I’m writing this tutorial because Configuring Devise’s Forget Password involves two things that are a pain in the ass to configure: EMAIL SETTINGS and DEVISE.

Don’t get me wrong, devise is the shit! I love it. But when you want to customize it as a noob, that shit is tough. Every other coder writing tutorials will act like it’s some walk in the park. It isn’t some walk in the park, it’s like a walk in the park with zombies coming after you and you’ve got lung problems. How about that?!

So, lol, this is embarrassing to admit, but I’ve had a website out there with around 50 active users and I forgot to configure the Forget Password functionality. And I tried to log into the site and I forgot my password. LOL, talk about ironic. I mean I didn’t do SHIT with the forget password thing, here’s all I did with it. I had a link to no where LOL. I’m probably the only one who thinks this is funny.

<a href="javascript:;" id="forget-password" class="forget-password">Forgot Password?</a>

Clearly the site had been in neglect.

I’m writing this post so I never have to do another google search on configuring Devise Forget Password.

<%= link_to("Forgot Password", new_user_password_path, id:"forget-password", class:"forget-password") %>

I’m afraid that was the easy part.

Step 2: Edit config/initializers/devise.rb

When you install Devise, they create a nice little initializer for you. Who knew? We have to configure devise’s email sender and we do that with the following line.

  config.mailer_sender = "Password Reset for Clash Progress <''>"

Except leave out the ’ ’. I add that because I’m an idiot and can’t figure out how to get that to display correctly without those damn “.

Step 3: No fucking clue… Let’s throw shit at the wall and see if it sticks

Start up the server rails s, visit http://localhost:3000/users/password/new, and type in your email address. I got this error.

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true Thanks for telling me where the hell to put that line of code.

A quick google search had me stumble upon this very informative stackoverflow.

Step 4: Configure Environments

Add this line of code to config/environments/development.rb

  config.actionmailer.defaulturl_options = { :host => 'localhost' } 

The make the line of code specific to your heroku app/custom domain in config/environments/production.rb

  config.actionmailer.defaulturl_options = { :host => '' } 

Of course you’ll want to add in your own url there. These are changes where we’ll need to restart the server. So let’s do that and test it again to see what happens.

Step 5: Test it again

OKAY, I got a "Good to go” message when I tested it on my server. Let’s see if I get an email. Holy shat it worked!

Deploy to heroku and test again! That’s my best advice. Fuck testing.

Important Side NotE!!!!

IT’S ALSO VERY IMPORTANT TO LOOK AT THE EMAIL YOU RECEIVE, CLICK THE LINK, AND ACTUALLY RESET YOUR PASSWORD. I ran into a problem with the link once and something was completely messed up with it. So be sure to test the ENTIRE process.

Post Content