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
end
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.new(params[:user])
if(request.post? and @user.save)
flash[:notice] = “Account Created Successfully”
redirect_to :controller => ‘yourloginsuccessfullycontrollername’
end
end
end
Now you could access registration page at http://yourhostname/user/register
June 18, 2007 at 11:16 am
thanks …..It was really helpful..
March 13, 2008 at 8:21 am
http://friendsofed.infopop.net/4/OpenTopic?a=tpc&s=989094322&f=9483093165&m=9461045161