diff options
Diffstat (limited to 'actionpack/lib/action_controller/metal/renderers.rb')
-rw-r--r-- | actionpack/lib/action_controller/metal/renderers.rb | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 6e9ce450ac..5272dc6cdb 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/class/attribute' -require 'active_support/core_ext/object/blank' require 'set' module ActionController @@ -49,14 +47,13 @@ module ActionController # is the value paired with its key and the second is the remaining # hash of options passed to +render+. # - # === Example # Create a csv renderer: # # ActionController::Renderers.add :csv do |obj, options| # filename = options[:filename] || 'data' # str = obj.respond_to?(:to_csv) ? obj.to_csv : obj.to_s - # send_data str, :type => Mime::CSV, - # :disposition => "attachment; filename=#{filename}.csv" + # send_data str, type: Mime::CSV, + # disposition: "attachment; filename=#{filename}.csv" # end # # Note that we used Mime::CSV for the csv mime type as it comes with Rails. @@ -69,7 +66,7 @@ module ActionController # @csvable = Csvable.find(params[:id]) # respond_to do |format| # format.html - # format.csv { render :csv => @csvable, :filename => @csvable.name } + # format.csv { render csv: @csvable, filename: @csvable.name } # } # end # To use renderers and their mime types in more concise ways, see @@ -91,9 +88,14 @@ module ActionController add :json do |json, options| json = json.to_json(options) unless json.kind_of?(String) - json = "#{options[:callback]}(#{json})" unless options[:callback].blank? - self.content_type ||= Mime::JSON - json + + if options[:callback].present? + self.content_type ||= Mime::JS + "#{options[:callback]}(#{json})" + else + self.content_type ||= Mime::JSON + json + end end add :js do |js, options| |