[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

validates_confirmation_of not working

J. mp

2/10/2007 11:41:00 PM

well, here I am again :)

validates_confirmation_of is not working

heres my model

class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :email, :first_name, :last_name, :screen_name,
:password
validates_confirmation_of :password
validates_presence_of :email, :first_name, :last_name, :screen_name,
:password
validates_format_of(:email,
:with =>
/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
:on => :create,
:message=>"has an invalid format")
#validates the uniqueness of email and screen name
validates_uniqueness_of :email, :screen_name



#end

def before_create
logger.info("password set to:"+password)
salt = [Array.new(6) {rand(256).chr}.join].pack("m").chomp
self.password_salt, self.password_hash =
salt, Digest::SHA256.hexdigest(password+salt)

end

#Authenticate a user
def self.authenticate(email, password)

user = User.find(:first, :conditions => ['email = ?', email])
if user.blank? ||
Digest::SHA256.hexdigest(password+ user.password_salt) !=
user.password_hash

raise "UserName or password invalid"
end
user

end

end

and my view


<p><label for="email">Email</label><br/>
<%= text_field 'user', 'email' %></p>

<p><label for="screen_name">Screen Name</label><br/>
<%= text_field 'user', 'screen_name' %></p>

<p><label for="first_name">First Name</label><br/>
<%= text_field 'user', 'first_name' %></p>

<p><label for="last_name">Last Name</label><br/>
<%= text_field 'user', 'last_name' %></p>


<p><label for="password">Password</label><br/>
<%= password_field 'user', 'password' %></p>

<p><label for="password_confirmation">Password Confirmation</label><br/>
<%= password_field 'user', 'password_confirmation'%></p>


however if I set differnt passwords in user creation it let me save the
user :(

--
Posted via http://www.ruby-....

1 Answer

Austin Ziegler

2/11/2007 12:09:00 AM

0

On 2/10/07, J. mp <joaomiguel.pereira@gmail.com> wrote:
> validates_confirmation_of is not working

This is a rails-specific question asked on the general Ruby mailing
list (which is bidirectionally mirrored to ruby-forum.com and the
comp.lang.ruby newsgroup); you're more likely to get a useful topical
answer to Rails questions on the proper Rails fora.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca