FormHelper and write-only fields


Until recently I used a User model with a write-only password field on
it. The idea is to pick that cleartext password up, perform some
salting and hashing on it and then write that to the database. So my
model used a method like this:

def password=(cleartext_password)
  @password = cleartext_password

Worked fine in combination with form_for and
f.password_field :password. But RC2 changed that and now complains
about missing method password_before_type_cast. The only workaround
I've found is to implement that method. (See
for a diff with a failing test in actionpack.)

Can anybody shed some light on this?

Thank you,

FormHelper needs a read method, too. You can return a blank string if
you like but you need to respond_to the field name in question.

You're most likely doing something that's not playing nicely with this
commit's change to value_before_type_cast:

I'm about to push a change related with this but definitely is not
going to solve your problem. You need a database field or a field
reader. Also your code doesn't work even before my commit. You can
check it out ...

Let's review it ...

object.respond_to?(method_name + "_before_type_cast") ?
object.send(method_name + "_before_type_cast") :

Your object doesn't respond_to password_before_type_cast so this code
ends trying to execute object.send('password') and you don't have a
reader neither.

Oliver, perhaps what you want to do is f.password_field :password, :value => ''
and instead of writing the password= method you can do attr_writer :password :wink:

I hope my message can clarify the situation.