views:

348

answers:

3

I have this problem all the time in my rails apps and I still need the correct solution. Whenever a user edits their own record the password field is being populated. I suspect its Firefox as setting @user.password = nil in the edit action doesn't help.

The problem is the password confirmation isn't populated so validation fails due to a miss-match.

I've tried the following:

<%= f.label :password %>
<%= f.password_field :password, :value => "", :autofill => false, :class => 'max' %>

But that doesn't do it. I've also tried :autofill => 'off' which doesn't work either.

Does anybody have any suggestions? Thanks.

+1  A: 

There are two solutions:

  1. tell firefox not to fill those fields;

  2. give password field a different name from "password".

giorgian
1. I cannot control the user. 2. Great idea which I'm sure would work, however I would have to modify the password field in quite a few projects, some with AuthLogic, some with RA etc etc.
tsdbrown
+2  A: 

Set autocomplete="off" in the form and the input tags

<form name="blah" autocomplete="off">
<input type="password" autocomplete="off">
</form>
Eddy
This has worked perfectly. Thank you!
tsdbrown
A: 

The HTML options are in there own hash so the syntax should look like this

<%= f.password_field :password, { :value => '' } %>

This should replace the value attribute in the response HTML.

triendeau
Thanks for the response although the syntax is perfectly valid as it is. The list of parameters after the method are still a hash without or without the brackets. Look at these examples: http://apidock.com/rails/ActionView/Helpers/FormHelper/password_field
tsdbrown
When last parameter is an hash, brackets are optional; neither mandatory nor forbidden.
giorgian
True enough, thanks for pointing out my own syntactic hangup. The :value => '' should be all that is needed though.
triendeau