We've built a new app which involves a lengthly registration process. We're using Rails 3 and devise for authentication using :confirmable.
No开发者_如何学运维w we've got to import a large set of existing users from an old system. We want this to be done manually to test the process.
So the problem is we don't want to send confirmation emails to these users.
Any suggestions how we can either suppress emails and still manually complete the registration process?
Dom
Looking at the confirmable
source code, it seems as if it won't send out any emails if the user is set to confirmed on create.
First off, you need to determine whether you want the newly created user to get an email or not. I'd suggest adding a checkbox to the form, or alternatively cross-referencing the email address against the old users table:
def create
# Form style
skip_email? = params[:user].delete(:skip_email)
# Old users style
skip_email? = !!OldUser.find_by_email(params[:user][:email])
@user = User.new(params[:user])
...
end
Assuming you've done one of the two, you'll have a boolean value of skip_email?
. Now you can do:
def create
skip_email? = true # See above
@user = User.new(params[:user])
@user.skip_confirmation!
if @user.save
...
end
end
skip_confirmation!
is a method Devise adds to the User model. You can find the Devise source code here.
精彩评论