I am using Rails 3.2 and Devise. I am wondering if Devise provides an "Email (address) Confirmation" field just like Password Confirmation for the user to type in a Password field and then type in a Password Confirmation field before the website sends out a confirmation email or processes the sign up registration. If not, must I add a email_confirmation and validate the User model (after rails g devise User)?
Thanks in advance
I haven't found if devise does what you ask (the question is referring to a second :email_confirmation field similar to :password_confirmation, 'confirmable' seems to be solely related to confirmation links). I had to do this as well and I figured out how to do it using builtin active record validation (rails 3.2.8, devise 2.1.2):
confirmation: true
to your email validation and :email_confirmation
to attr_accessible
.:email_confirmation
field.As an example, in your model (not assuming other validations or attr_accessibles):
attr_accessible :email, :email_confirmation
validates :email, confirmation: true
which will use the builtin active record 'confirmation' validation (the same as for passwords). Finally, in your view(s) you'll need to add something like:
<div><%= f.label :email_confirmation %>
<%= f.email_field :email_confirmation %></div>
There may be a cleaner way but this worked for me. However, my only experience with devise so far has been when adding it to existing models, I haven't used it when it's generating the models for you (presumably it's mostly the same).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With