Skip to content
Browse files

Merge pull request #2036 from Bodacious/tag_helper_data_fix

TagHelper creates invalid data attributes when value is a BigDecimal
  • Loading branch information...
2 parents 8067857 + 56aabfd commit 319903bde56bae0f7c83a049bb44377522699bd8 @rafaelfranca rafaelfranca committed May 17, 2012
Showing with 5 additions and 4 deletions.
  1. +3 −2 actionpack/lib/action_view/helpers/tag_helper.rb
  2. +2 −2 actionpack/test/template/tag_helper_test.rb
View
5 actionpack/lib/action_view/helpers/tag_helper.rb
@@ -154,8 +154,9 @@ def tag_options(options, escape = true)
def data_tag_option(key, value, escape)
key = "data-#{key.to_s.dasherize}"
- value = value.to_json if !value.is_a?(String) && !value.is_a?(Symbol)
-
+ unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(BigDecimal)
+ value = value.to_json
+ end
tag_option(key, value, escape)
end
View
4 actionpack/test/template/tag_helper_test.rb
@@ -118,8 +118,8 @@ def test_disable_escaping
def test_data_attributes
['data', :data].each { |data|
- assert_dom_equal '<a data-a-number="1" data-array="[1,2,3]" data-hash="{&quot;key&quot;:&quot;value&quot;}" data-string="hello" data-symbol="foo" />',
- tag('a', { data => { :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } })
+ assert_dom_equal '<a data-a-float="3.14" data-a-big-decimal="-123.456" data-a-number="1" data-array="[1,2,3]" data-hash="{&quot;key&quot;:&quot;value&quot;}" data-string="hello" data-symbol="foo" />',
+ tag('a', { data => { :a_float => 3.14, :a_big_decimal => BigDecimal.new("-123.456"), :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } })
}
end
end

0 comments on commit 319903b

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