This project is archived and is in readonly mode.
FormHelper problem with write-only fields
Reported by Oliver Eilhard | August 27th, 2010 @ 09:24 AM
With 3.0 RC2 I'm having problems with models that have write-only fields that are not backed by a database column, e.g. a User model with a password field.
I will provide a new test in form_helper_test.rb
that fails with RC2 but succeeds with RC.
This is probably due to the changes in 8141f0894ecf869ee11f077e5b49e06669790632 (see ticket #3374.
The only workaround I've found is implementing the
xyz_before_type_cast
method. Is this the way it's
supposed to work?
Comments and changes to this ticket
-
Oliver Eilhard August 27th, 2010 @ 09:29 AM
- Tag set to form_helper, patch
This patch adds a failing test to
form_helper_test.rb
. -
Santiago Pastorino August 27th, 2010 @ 12:30 PM
- Importance changed from to Low
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") : object.send(method_name)
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 ;) -
Repository August 27th, 2010 @ 01:08 PM
- State changed from new to committed
(from [f95ba5c262bfd713f0a2fc656f8e645d3eea60f2]) Make InstanceTagMethods#value_before_type_cast raise if the model don't respond to attr_before_type_cast or attr method
[#3374] [#5471 state:committed] http://github.com/rails/rails/commit/f95ba5c262bfd713f0a2fc656f8e64...
-
Repository August 27th, 2010 @ 01:09 PM
(from [3ba8e3100548f10fce0c9784981a4589531476dd]) Make InstanceTagMethods#value_before_type_cast raise if the model don't respond to attr_before_type_cast or attr method
[#3374] [#5471 state:committed] http://github.com/rails/rails/commit/3ba8e3100548f10fce0c9784981a45...
-
Oliver Eilhard August 27th, 2010 @ 01:51 PM
I'm still puzzled why it did work up to 3.0 RC, but your help is greatly appreciated. I'm going with the
f.password_field :password, :value => ''
and that's fine with me. Thanks, Santiago. -
Santiago Pastorino August 27th, 2010 @ 04:28 PM
Doesn't work for me on Rails 3 RC.
I'm uploading the example for you to see, i'm getting as expected according to the code :) ...undefined method `password' for #<Post id: nil, title: nil, created_at: nil, updated_at: nil> Extracted source (around line #20): 17: </div> 18: <div class="field"> 19: <%= f.label :password %><br /> 20: <%= f.password_field :password %> 21: </div> 22: <div class="actions"> 23: <%= f.submit %>
-
Oliver Eilhard August 27th, 2010 @ 04:41 PM
Thanks again. Sorry for causing so much work. Next time, I'll do better testing... promised. :-)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 5471 FormHelper problem with write-only fields [#3374] [#5471 state:committed] http://github.com/rails/...
- 3374 text_field() does not use overridden model accessors [#3374] [#5471 state:committed] http://github.com/rails/...
- 3374 text_field() does not use overridden model accessors [#3374] [#5471 state:committed] http://github.com/rails/...
- 5471 FormHelper problem with write-only fields [#3374] [#5471 state:committed] http://github.com/rails/...
- 5508 OpenStruct objects can no longer be used in form helpers You should check this whole thread https://rails.lighthou...