# Users generator?

**URL:** <https://www.ruby-forum.com/t/users-generator/150859>\
**Category:** Rails\
**Created:** [October 14, 2008, 10:26am UTC](https://www.ruby-forum.com/t/users-generator/150859 "2008-10-14T10:26:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conrad\_Owen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9e5f3/32.png) [@Conrad\_Owen](https://www.ruby-forum.com/u/Conrad_Owen)\
**Post date:** [October 14, 2008, 10:26am UTC](https://www.ruby-forum.com/t/users-generator/150859/1 "2008-10-14T10:26:31Z")

</div>

I was just writing a User model for possibly the fourth time since I  
picked up Rails last week (I’ve been going through tons of examples),  
which seems to violate the DRY principle. I was wondering if Rails had  
any basic User generator somewhere, or one in the pipelines, or a  
plugin?

Obviously different apps write User for different things, but this  
generator could just be slightly more advanced scaffolding, with  
methods provided for salts, signup, login, etc.

Or maybe I’m still just too inexperienced to really know?

---

<div class="post-metadata">

**Author:** ![Conrad\_Owen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9e5f3/32.png) [@Conrad\_Owen](https://www.ruby-forum.com/u/Conrad_Owen)\
**Post date:** [October 14, 2008, 10:45am UTC](https://www.ruby-forum.com/t/users-generator/150859/2 "2008-10-14T10:45:16Z")

</div>

There is plugin that is generating pretty standard model and  
controller for handling login/logout of users.

[http://agilewebdevelopment.com/plugins/restful\_authentication](http://agilewebdevelopment.com/plugins/restful_authentication)

I do not use it personally, but it’s good to look at code it  
generates.

---

<div class="post-metadata">

**Author:** ![Conrad\_Owen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9e5f3/32.png) [@Conrad\_Owen](https://www.ruby-forum.com/u/Conrad_Owen)\
**Post date:** [October 14, 2008, 11:52am UTC](https://www.ruby-forum.com/t/users-generator/150859/3 "2008-10-14T11:52:53Z")

</div>

I’m still fairly a noob to rails myself. I’m more used to PHP, Java,  
and C++ mostly. It definitely does throw you through a loop a few  
times.

Anyhow, to clarify, if you are asking if there is an extension or  
plugin that will generate actual user accounts for you, that isn’t  
going to happen unfortunately. If you are working on writing some sort  
of login or authentication system, my suggestion is either manually  
create your model and controller, or do it via scaffolding.

So lets say you were creating a rails app called login. So then you  
have to decide how you want the authentication to take place. A very  
simple method is reading values from an xml file or other text.  
However as we all know, that is unsecure and bad practice all the way  
around. So logically, lets just use a database to save your users.

For this example, we’ll use mysql. So lets crap the imaginary app.

prompt\>rails -d mysql login

Ok, now that is created, we’ll want to create our database. Since the  
default naming convention in the /app/config/database.yml file is  
appname\_development, we want to call it login\_development. So we’ll  
type:

prompt\>mysqladmin -u root create login\_development.

Now lets go into our directory  
prompt\>cd login

Now, the easiest way to generate everything all at once is  
scaffolding. To go about this, you’ll type:  
prompt\>script/generate scaffold users /

> username:string password:string first\_name:string last\_name:string

From there you’ll type:  
prompt\>rake db:migrate

So your table on the login\_development database has been created with  
the fields/columns username, password, first\_name, and last\_name all  
with string or as mysql calls it VARCHAR data type.

And from there, you would beging setting up your back-end  
functionality and user interface.

And that’s about it. Its fairly simple with rails. Hope this helps to  
get you started at least. Let know if if you have any questions.
