Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## view, new.rhtml
- <%= start_form_tag :action => 'create'%>
- <%= error_messages_for 'user' %>
- <p>Screen Name: <%= text_field 'user', 'screen_name' %></p>
- <p>Email Address: <%= text_field 'email', 'email' %>
- <p>Password: <%= password_field 'user', 'password', :size => 10 %></p>
- <p>Confirm Password: <input type="password" name="user[confirm_password]" id ="user_confirm_password" size="10"></p>
- <p>Zip Code: <%= text_field 'user', 'zip_code', :size => 5, :maxlength => 5 %></p>
- <%= submit_tag 'Create New User' %>
- <%= end_form_tag %>
- ## model, users.rb
- class User < ActiveRecord::Base
- validates_presence_of :screen_name
- has_many :emails
- has_many :logins
- attr_accessor :password, :confirm_password
- def validate
- errors.add(:password, "not the same") unless password == confirm_password
- end
- def before_save
- self.password_sha1 = Digest::SHA256.hexdigest(password) if password
- end
- end
- ## controller, user_registration_controller.rb
- class UserRegistrationController < ApplicationController
- verify :method => :post, :only => [ :destroy, :create, :update ],
- :redirect_to => { :action => :list }
- def new
- @user = User.new
- @email = Email.new
- end
- def create
- @user = User.new(params[:user])
- @user.emails << Email.new(params[:email])
- if @user.save
- flash[:notice] = "New user created successfully"
- redirect_to :action => 'whereever'
- else
- redirect_to :action => 'new'
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement