Skip to content

HTTPS clone URL

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
View
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")
end
end
View
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
end
@@ -233,6 +243,13 @@ def test_text_field_with_custom_type
text_field("user", "email", :type => "email")
end
+ def test_text_field_from_a_user_defined_method
+ @developer = Developer.new
+ 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
assert_dom_equal(
'<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

@tilsammans

Yes! Thank you.

@spastorino
Owner

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

@masterkain

This probably broke searchlogic, already opened an issue here: http://github.com/binarylogic/searchlogic/issues/issue/111

@spastorino
Owner

@masterkain nice!!!

@jduff

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).

@spastorino
Owner

@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 ;)

@jduff

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.