Build A Simple Registration Form Using Rails

May 30, 2007

In Rails you could simply build a Form based on model using “form_for” helper.

Assume your “users” table has login, password, name, email columns. Thats mapped as “User” Model using ActiveRecord (in app/models/user.rb file)

class User < ActiveRecord::Base


Now you could build a registration form (in views/register.rhtml file) as

<% form_for :user do |f| %>
<p> Your Name: <br />  <%= f.text_field :name %></p>
<p>  Login ID:<br /><%= f.text_field :login %></p>
<p>  Password: <br />  <%= f.text_field :password %></p>
<p>  Email:<br /> <%= f.text_field :email %></p>
<p><%= submit_tag “Create Account” %></p>
<% end %>

To complete things, write controller logic to save data (in file apps/controllers/user_controller.rb)

class UserController < ApplicationController 
     def register
         @user =[:user])
             if( and
                   flash[:notice] = “Account Created Successfully”
                   redirect_to :controller => ‘yourloginsuccessfullycontrollername’

Now you could access registration page at http://yourhostname/user/register 


14 Responses to “Build A Simple Registration Form Using Rails”

  1. subramanian kaushik Says:

    thanks …..It was really helpful..

  2. David Says:

    umm how do i connect this to a MySql database? e mail me at

  3. nlakkakula Says:

    David … In rails, the database linkage is done by ActiveRecord and you configure that in yaml file in config folder…. basically this registration form uses “User” Model means connected to “users” table in your db…

  4. Laryn Says:

    I think your site is very good and complete, but the information you have here,

  5. Theodore Says:

    I don’t want to see threads like this whonews.,

  6. sandrar Says:

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  7. Sad12 Says:

    What kind of rational incentive the participant have as the time nears midnight and the number reaches the limit? ,

  8. Roberta Says:

    good work

  9. IngaAbusia Says:

    Like a crazy Microsoft!

  10. BillTusy Says:

    If your ssd drive fails, all is not lost.

    ssd drive data recovery

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: