Prashant Tiwari
2006-Apr-04 08:38 UTC
[Rails] how to perform client side validations in RoR?
Hi, I have a form for user registration. In that form there are fields for password & confirm_password. Now in my database there is column corresponding to password field. Now at clicnt side I want to validate equality of password & confirm_password field. How to do that? I have downloaded one password validator plugin & tried to used it. But it requirs two seperate fields in database for password & confirm passowrd. & I don''t want field for confirm_password in database. How to do that? can we use Some client side validations here? If yes ..how? please tell me. Thanx in advance. Prash -- Posted via http://www.ruby-forum.com/.
Bryan Buecking
2006-Apr-04 08:50 UTC
[Rails] how to perform client side validations in RoR?
Prashant Tiwari wrote:> I have a form for user registration. In that form there are fields for > password & confirm_password. Now in my database there is column > corresponding to password field. Now at clicnt side I want to validate > equality of password & confirm_password field. How to do that? > I have downloaded one password validator plugin & tried to used it. But > it requirs two seperate fields in database for password & confirm > passowrd. & I don''t want field for confirm_password in database. How to > do that? > can we use Some client side validations here? If yes ..how? please tell > me.You might want to look up validates_confirmation_of ie. db users table id, login, password class User < ActiveRecord::Base validates_confirmation_of :password end Your controller could be something like: class UserController < ApplicationController def signup @user = User.new(params[:user]) if @user.save render_partial ''signup_success'' else render_partial ''signup'', @user end end and in your view <div id="signup_form_area"> <%= form_remote_tag :update => ''signup_form_area'', :url => { :controller => ''user_controller'', :action=> ''signup'' }%> <% if !@user.nil? %> <%= error_message_on ''user'', ''login'', ''User '' %> <% end %> <label for="user_login">username:</label><br/> <%= text_field "user", "login", :size => 30 %><br/> <% if !@user.nil? %> <%= error_message_on ''user'', ''password'', ''Password '' %> <% end %> <label for="user_password">password:</label><br/> <%= password_field "user", "password", :size => 30 %><br/> <label for="user_password_confirmation">confirm password:</label><br/> <%= password_field "user", "password_confirmation", :size => 30 %><br/> <input type="submit" value="add user»" class="primary" /> <%= end_form_tag %> </div> NOTE: this implementation uses Ajax, but you could easily do w/o. -- Bryan Buecking