Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Makes form_helper use overriden model accessors

[#3374 state:committed]
  • Loading branch information...
commit fb0bd8c1092db51888ec4bb72af6c595e13c31fa 1 parent f78de68
@spastorino spastorino authored
6 actionpack/lib/action_view/helpers/form_helper.rb
@@ -1005,9 +1005,9 @@ def value(object, method_name)
def value_before_type_cast(object, method_name)
unless object.nil?
- object.respond_to?(method_name + "_before_type_cast") ?
- object.send(method_name + "_before_type_cast") :
- object.send(method_name)
+ object.respond_to?(method_name) ?
+ object.send(method_name) :
+ object.send(method_name + "_before_type_cast")
17 actionpack/test/template/form_helper_test.rb
@@ -4,6 +4,16 @@
class FormHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormHelper
+ class Developer
+ def name_before_type_cast
+ "David"
+ end
+ def name
+ "Santiago"
+ end
+ end
def form_for(*)
@output_buffer = super
@@ -233,6 +243,13 @@ def test_text_field_with_custom_type
text_field("user", "email", :type => "email")
+ def test_text_field_from_a_user_defined_method
+ @developer =
+ assert_dom_equal(
+ '<input id="developer_name" name="developer[name]" size="30" type="text" value="Santiago" />', text_field("developer", "name")
+ )
+ end
def test_check_box
'<input name="post[secret]" type="hidden" value="0" /><input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" />',

8 comments on commit fb0bd8c


Yes! Thank you.


You're welcome this patch is around since Rails used track, i don't know why nobody did a patch yet


This probably broke searchlogic, already opened an issue here:


@masterkain nice!!!


This commit causes issue with Time fields in MySQL. Instead of rendering the time (12:30) from the database it is now rendering the casted DateTime (Sat Jan 01 12:30:00 UTC 2000).


@jduff can you provide a test case? also it would be awesome if you can add a ticket on lighthouse and assign to me. Really appreciate your comment ;)


Ya, I've been looking at it with Chris who opened the ticket. It seems like before it was just getting the string from the database and now you get back a time object. I guess the best solution is to pass :value => time.to_s(:short) or whatever formatting you want to the input call. This way you're controlling the formatting and not just displaying whatever happens to be in the database. It was just a little surprising when moving between the RC versions.

Please sign in to comment.
Something went wrong with that request. Please try again.