aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-05-17 11:01:21 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-05-17 11:01:21 -0700
commit319903bde56bae0f7c83a049bb44377522699bd8 (patch)
tree09f38194aa5b9f2373a6fd240386b1ce1d72f258 /actionpack
parent8067857bdfcea7bb1f916613dabfc96502932fbf (diff)
parent56aabfd559459da6fb8e736ee5c21a139870cd5a (diff)
downloadrails-319903bde56bae0f7c83a049bb44377522699bd8.tar.gz
rails-319903bde56bae0f7c83a049bb44377522699bd8.tar.bz2
rails-319903bde56bae0f7c83a049bb44377522699bd8.zip
Merge pull request #2036 from Bodacious/tag_helper_data_fix
TagHelper creates invalid data attributes when value is a BigDecimal
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