# Validates\_confirmation\_of not working

**URL:** <https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159>\
**Category:** Rails\
**Created:** [October 24, 2007, 11:56am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159 "2007-10-24T11:56:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 11:56am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/1 "2007-10-24T11:56:29Z")

</div>

Hello to everyone,

Well, very frustrated with this one because I am following the example  
straight from the documentation and it is not working.

First when I try:

validates\_confirmation\_of :password, :on =\> :password\_update  
(password\_update is a def in my User model which works fine without  
this validation in please)

I get the following error:

TypeError in UsersController#update\_password  
nil is not a symbol

[Full trace at the end of this message.]

However, if I do only this:

validates\_confirmation\_of :password

It jumps over the validation because no matter what I put in the  
password and password\_confirmation fields, changes are always saved.

Any advice, greatly appreciated.

Thank you,

GPB

* * *

Full trace for validates\_confirmation\_of :password, :on  
=\> :password\_update

C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
validations.rb:296:in `send' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ validations.rb:296:in`validates\_each’  
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/  
validations.rb:336:in `validates_confirmation_of' #{RAILS_ROOT}/app/models/user.rb:8 C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:203:in`load\_without\_new\_constant\_marking’  
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:203:in `load_file' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:342:in`new\_constants\_in’  
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:202:in `load_file' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:94:in`require\_or\_load\_without\_engine\_additions’  
#{RAILS\_ROOT}/vendor/plugins/engines/lib/engines/rails\_extensions/  
dependencies.rb:139:in `require_or_load' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:248:in`load\_missing\_constant’  
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:452:in `const_missing' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:464:in`const\_missing’  
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:260:in `load_missing_constant' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:468:in`const\_missing’  
#{RAILS\_ROOT}/app/controllers/application.rb:9:in `admin_authenticate' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:456:in`send’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
filters.rb:456:in `call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:435:in`call’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
filters.rb:637:in `call_filter' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:619:in`perform\_action\_without\_benchmark’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' C:/ruby/lib/ruby/1.8/benchmark.rb:293:in`measure’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ rescue.rb:83:in`perform\_action’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:430:in `send' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:430:in`process\_without\_filters’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
filters.rb:624:in `process_without_session_management_support' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ session_management.rb:114:in`process’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
base.rb:330:in `process' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in`dispatch’  
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:  
113:in `handle_dispatch' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in`service’  
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in`run’  
C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in`start’  
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in`start’  
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in`start’  
C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in`start’  
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:63:in  
`dispatch' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/ webrick.rb:59 C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`gem\_original\_require’  
C:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:495:in`require’  
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/  
dependencies.rb:342:in `new_constants_in' C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:495:in`require’  
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
C:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
script/server:3

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/2 "2007-10-24T12:03:30Z")

</div>

On 24 Oct 2007, at 10:55, GPB wrote:

> (password\_update is a def in my User model which works fine without  
> this validation in please)

You can’t do that. :on must be one of :save, :create or :update

Fred

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 12:05pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/3 "2007-10-24T12:05:15Z")

</div>

Hello again…

I will answer my first question.

I thought the :on option could take any def from the controller and  
apply the validation only when that action was called. But now I see  
it only takes :save, :create and :update.

However, even when putting :update as the :on option, it is still  
bypassing the validation even though the data in the fields are not  
equal.

And one correction in my previous post, password\_update is a def in my  
controller, not in my model, like I stated previously.

Thanks again,

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 12:32pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/4 "2007-10-24T12:32:46Z")

</div>

On 24 Oct 2007, at 11:04, GPB wrote:

> Hello again…
> 
> I will answer my first question.
> 
> I thought the :on option could take any def from the controller and  
> apply the validation only when that action was called. But now I see  
> it only takes :save, :create and :update.

It’s not a controller thing (how would the model know the action that  
was causing it to be saved), it’s a model thing: is the instance  
being saved for the first time or all the time

> However, even when putting :update as the :on option, it is still  
> bypassing the validation even though the data in the fields are not  
> equal.

Can’t guess without seeing at least some code.

Fred

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 1:16pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/5 "2007-10-24T13:16:03Z")

</div>

Hi Fred,

I went ahead and coded the validation myself.

However, I think the problem has to do with this, used for the  
encryption of the password.

def password=(value)  
if !value.blank?  
write\_attribute(“password”, Digest::SHA1.hexdigest(value))  
end  
end

Because I got it to the point that the validation worked, but it  
always returned that the values didn’t match.

When I took out the lines for encryption it worked perfectly. So it  
seems it looks to compare the password string encrypted with the  
password\_confirmation string not encrypted.

Care to explain how to work around this?

Thank you,

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 1:16pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/6 "2007-10-24T13:16:38Z")

</div>

Hi DHH, you are right, it was a type on my part when writing the post,  
anyway Fred already explained I can’t do that for the :on condition.

Either way, thank you.

On Oct 24, 12:17 pm, Dhh R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 12:17pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/7 "2007-10-24T12:17:05Z")

</div>

validates\_confirmation\_of :password, :on =\> :password\_update  
(password\_update is a def in my User model which works fine without  
this validation in please)

I get the following error:

TypeError in UsersController#update\_password

Well i am a bit confused why u have called password\_update and you are  
getting update\_password error…  
check your model once again  
DHH

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 1:18pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/8 "2007-10-24T13:18:58Z")

</div>

On 24 Oct 2007, at 12:14, GPB wrote:

> ```
> if !value.blank?
> 
> ```

I think if you do the hashing of the password in a before\_update  
you’ll be ok.

Fred

---

<div class="post-metadata">

**Author:** ![GPB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@GPB](https://www.ruby-forum.com/u/GPB)\
**Post date:** [October 24, 2007, 1:27pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/118159/9 "2007-10-24T13:27:46Z")

</div>

Thank you Fred, that worked.

On Oct 24, 1:18 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
