Devise - create user account with confirmed without sending out an email?

Solution 1:

The confirm callback happens after create, so it's happening on line 1 of your example, before you set confirmed_at manually.

As per the comments, the most correct thing to do would be to use the method provided for this purpose, #skip_confirmation!. Setting confirmed_at manually will work, but it circumvents the provided API, which is something which should be avoided when possible.

So, something like:

user = User.new(user_attrs)
user.skip_confirmation!
user.save!

Original answer:

If you pass the confirmed_at along with your create arguments, the mail should not be sent, as the test of whether or not an account is already "confirmed" is to look at whether or not that date is set.

User.create(
  :email => data['email'], 
  :password => Devise.friendly_token[0,20], 
  :confirmed_at => DateTime.now
)

That, or just use new instead of create to build your user record.

Solution 2:

If you just want to prevent sending the email, you can use #skip_confirmation_notification, like so:

user = User.new(your, args)
user.skip_confirmation_notification!
user.save!

See documentation

Skips sending the confirmation/reconfirmation notification email after_create/after_update. Unlike #skip_confirmation!, record still requires confirmation.