aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-xactionpack/lib/action_controller/base.rb1
-rw-r--r--actionpack/lib/action_controller/mime_type.rb10
2 files changed, 9 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 9a3ab651ac..4630103119 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -826,6 +826,7 @@ module ActionController #:nodoc:
render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status])
elsif json = options[:json]
+ json = json.to_json unless json.is_a?(String)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
response.content_type = Mime::JSON
render_for_text(json, options[:status])
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb
index 7c7faefa46..29b7723d76 100644
--- a/actionpack/lib/action_controller/mime_type.rb
+++ b/actionpack/lib/action_controller/mime_type.rb
@@ -52,12 +52,18 @@ module Mime
EXTENSION_LOOKUP[extension]
end
- def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [])
+ # Registers an alias that's not usd on mime type lookup, but can be referenced directly. Especially useful for
+ # rendering different HTML versions depending on the user agent, like an iPhone.
+ def register_alias(string, symbol, extension_synonyms = [])
+ register(string, symbol, [], extension_synonyms, true)
+ end
+
+ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false)
Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms)
SET << Mime.send(:const_get, symbol.to_s.upcase)
- ([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last }
+ ([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last } unless skip_lookup
([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last }
end