# Validating user's e-mail address with hashed link

**URL:** <https://www.ruby-forum.com/t/validating-users-e-mail-address-with-hashed-link/130506>\
**Category:** Rails\
**Created:** [February 28, 2008, 9:20pm UTC](https://www.ruby-forum.com/t/validating-users-e-mail-address-with-hashed-link/130506 "2008-02-28T21:20:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 28, 2008, 9:20pm UTC](https://www.ruby-forum.com/t/validating-users-e-mail-address-with-hashed-link/130506/1 "2008-02-28T21:20:33Z")

</div>

Hi everyone-

This is obviously a pattern, can someone suggest pseudocode, including  
where to put the mailing?

I was thinking in the model:

aftercreate:

- create hash for link
- send e-mail with clickable link

in the view

- if the create is successful, redirect to “you’ll be getting an e-  
mail” page

in controller:

- create an action called confirmation that takes hash and login  
from GET
- change status of user to confirmed

is there an easier (built-in to rails) approach?

Thanks,  
Dino

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 28, 2008, 9:38pm UTC](https://www.ruby-forum.com/t/validating-users-e-mail-address-with-hashed-link/130506/2 "2008-02-28T21:38:09Z")

</div>

look at restful\_authentication, it provides a method for activating a  
user with an activation code and acts\_as\_state\_machine

[http://svn.techno-weenie.net/projects/plugins/restful\_authentication/](http://svn.techno-weenie.net/projects/plugins/restful_authentication/)

Mike

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 29, 2008, 6:29am UTC](https://www.ruby-forum.com/t/validating-users-e-mail-address-with-hashed-link/130506/3 "2008-02-29T06:29:05Z")

</div>

validates\_format\_of :email, :with =\>  
/^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i,  
:message =\> “is not valid”

Try this…
