aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorBodacious <gavin@katanacode.com>2012-05-17 18:15:43 +0100
committerBodacious <gavin@katanacode.com>2012-05-17 18:15:43 +0100
commit56aabfd559459da6fb8e736ee5c21a139870cd5a (patch)
tree866f65fb54ce3207640139c1d48736bcb75dc50d /actionpack
parent6ada771a08196d8a5d790f8b4b2224aa8e1748b3 (diff)
downloadrails-56aabfd559459da6fb8e736ee5c21a139870cd5a.tar.gz
rails-56aabfd559459da6fb8e736ee5c21a139870cd5a.tar.bz2
rails-56aabfd559459da6fb8e736ee5c21a139870cd5a.zip
Fixed tag_helper data-attribute bug with BigDecimals
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/tag_helper.rb5
-rw-r--r--actionpack/test/template/tag_helper_test.rb4
2 files changed, 5 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index d5cd60e8a1..498be596ad 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -154,8 +154,9 @@ module ActionView
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
diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb
index 7161d107b3..f0a7ce0bc9 100644
--- a/actionpack/test/template/tag_helper_test.rb
+++ b/actionpack/test/template/tag_helper_test.rb
@@ -118,8 +118,8 @@ class TagHelperTest < ActionView::TestCase
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