Skip to content

Commit 6042067

Browse files
author
David Heinemeier Hansson
committed
Changed the default ActiveSupport.use_standard_json_time_format from false to true and
ActiveSupport.escape_html_entities_in_json from true to false to match previously announced Rails 3 defaults [DHH]
1 parent 532b116 commit 6042067

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

activesupport/CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
*Edge*
22

3+
* Changed the default ActiveSupport.use_standard_json_time_format from false to true and
4+
ActiveSupport.escape_html_entities_in_json from true to false to match previously announced Rails 3 defaults [DHH]
5+
36
* Added Object#presence that returns the object if it's #present? otherwise returns nil [DHH/Colin Kelley]
47

58
* Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls [DHH]

activesupport/lib/active_support/json/encoding.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def escape(string)
114114
end
115115
end
116116

117-
self.escape_html_entities_in_json = true
117+
self.use_standard_json_time_format = true
118+
self.escape_html_entities_in_json = false
118119
end
119120

120121
CircularReferenceError = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)

activesupport/lib/active_support/time_with_zone.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ module ActiveSupport
3232
# t.is_a?(Time) # => true
3333
# t.is_a?(ActiveSupport::TimeWithZone) # => true
3434
class TimeWithZone
35-
3635
def self.name
3736
'Time' # Report class name as 'Time' to thwart type checking
3837
end
@@ -114,9 +113,9 @@ def xmlschema(fraction_digits = 0)
114113
end
115114
alias_method :iso8601, :xmlschema
116115

117-
# Coerces the date to a string for JSON encoding.
118-
#
119-
# ISO 8601 format is used if ActiveSupport::JSON::Encoding.use_standard_json_time_format is set.
116+
# Coerces the date to a string for JSON encoding. The default format is ISO 8601. You can get
117+
# %Y/%m/%d %H:%M:%S +offset style by setting ActiveSupport::JSON::Encoding.use_standard_json_time_format
118+
# to false.
120119
#
121120
# ==== Examples
122121
#

railties/lib/rails/generators/rails/app/templates/config/initializers/new_rails_defaults.rb

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
# for Rails 3. You can remove this initializer when Rails 3 is released.
55

66
if defined?(ActiveRecord)
7-
# Include Active Record class name as root for JSON serialized output.
8-
ActiveRecord::Base.include_root_in_json = true
9-
107
# Store the full class name (including module namespace) in STI type column.
118
ActiveRecord::Base.store_full_sti_class = true
12-
end
13-
14-
# Use ISO 8601 format for JSON serialized times and dates.
15-
ActiveSupport.use_standard_json_time_format = true
16-
17-
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
18-
# if you're including raw json in an HTML page.
19-
ActiveSupport.escape_html_entities_in_json = false
9+
end

0 commit comments

Comments
 (0)