简体   繁体   中英

skip confirmation e-mail in development with devise

I am using devise and I want to be able to skip the confirmation e-mail while I am in development mode. Since my application can't send e-mail while running on my local machine, I will just get the alert message saying that you need to be confirmed before accessing the application.

Devise has also a method skip_confirmation! that you can call on the model before saving it to avoid sending the mail. It simply sets the confirmed_at attribute which results in skipping the mail sending.

try Letter Opener gem from Ryan Bates

https://github.com/ryanb/letter_opener

it will open the email in the browser without sending it. You don't want to be skipping stuff out if you're in development because stuff will get missed/forgotten about.

As simple as that

user=User.new
user.email="you@email.id"
user.password="yourPassword"
user.skip_confirmation!
user.save

或者您可以在您的开发环境中尝试MailCatcher

If you want a really light weight way to do this, look in your terminal after registering - the rails output shows the email that got sent, you can copy-paste the confirmation link, confirming the account and then continue testing.

crude, but effective.

在 Rails 3 中,您可以使用“拦截器”来重新路由您的开发电子邮件,如Railscast 206 中所述

Take your model for devise. Commonly Its user.rb. And remove or comment the config comfirmable . This will prevent the process of confirmation

Devise uses ActionMailer to send emails. In test mode, ActionMailer shouldn't actually send any emails.

Check out this tutorial for an explanation on ActionMailer and testing environments.

So, depending on the environment, you can basically turn delivery off, while not affecting your actual tests. You just have to specify that option in the environments/test.rb file.

simmilar to letter_opener gem (recommended by John Beynon above) there is a gem called mailcatcher which works on SMTP level.

basically you configure SMTP on your Rails app to point to port under which mailcatcher run on local machine and you have mailcatcher browser on other port to read the emails

more info https://github.com/sj26/mailcatcher

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM