# Creating users for Recipes authentication method

**URL:** <https://www.ruby-forum.com/t/creating-users-for-recipes-authentication-method/114335>\
**Category:** Rails\
**Created:** [September 11, 2007, 2:14pm UTC](https://www.ruby-forum.com/t/creating-users-for-recipes-authentication-method/114335 "2007-09-11T14:14:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [September 11, 2007, 2:14pm UTC](https://www.ruby-forum.com/t/creating-users-for-recipes-authentication-method/114335/1 "2007-09-11T14:14:53Z")

</div>

If using recipe 31 in Mr. Fowler’s book, one ought really to add a form  
for user creation. Something like this (within user\_controller.rb),  
perhaps:

def register  
@user = User.create  
if request.post?  
@user.attributes = params[:user]  
if @user.save  
flash[:notice] = “Your request has been saved.”  
redirect\_to :controller =\> ‘user’, :action =\> ‘register\_success’,  
:user =\> @user.id and return  
else  
flash[:error] = “Your request could not be saved.”  
redirect\_to :controller =\> ‘user’, :action =\> ‘register’, :method  
=\> ‘get’ and return  
end  
end  
end

The way the user model works is that it does not store the user’s  
password, but the password\_salt and password\_hash. The password method  
generates these. A means of checking that the password and confirmation  
from the form in register.rhtml match, and that the password consists of  
the approved characters is needed.

What would be the best place to put this - in the user model or as part  
of this register method? If the latter, does anyone have any suggestions  
as to a good way to do this?

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [September 11, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/creating-users-for-recipes-authentication-method/114335/2 "2007-09-11T16:31:54Z")

</div>

IMO, validation always belongs in the model.

On Sep 11, 8:14 am, Milo T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [September 11, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/creating-users-for-recipes-authentication-method/114335/3 "2007-09-11T16:35:12Z")

</div>

Jeff Emminger wrote:

> IMO, validation always belongs in the model.

Thanks - I will indeed put it there.

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [September 11, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/creating-users-for-recipes-authentication-method/114335/4 "2007-09-11T17:26:22Z")

</div>

Milo T. wrote:

> The way the user model works is that it does not store the user’s  
> password, but the password\_salt and password\_hash. The password method  
> generates these. A means of checking that the password and confirmation  
> from the form in register.rhtml match, and that the password consists of  
> the approved characters is needed.
> 
> What would be the best place to put this - in the user model or as part  
> of this register method? If the latter, does anyone have any suggestions  
> as to a good way to do this?

If you have a chance to pick up the Agile Web D. with Rails  
book from the same publisher, there is similar code included in chapter  
11. The validation is enforced by the model (via validates\_presence\_of,  
et. al.) while the action of saving and displaying the resulting message  
is done in the controller. I’ve been carrying that book around with me  
anywhere I go for the last month 🙂
