File: rails_renderer.rb

package info (click to toggle)
ruby-acts-as-api 1.0.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 624 kB
  • sloc: ruby: 2,366; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 588 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module ActsAsApi
  # Contains rails specific renderers used by acts_as_api to render a jsonp response
  #
  # See ActsAsApi::Config about the possible configurations
  module RailsRenderer
    def self.setup
      ActionController.add_renderer :acts_as_api_jsonp do |json, options|
        json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)

        if options[:callback].present?
          json = "#{options[:callback]}(#{json}, #{response.status})"
          self.content_type = Mime[:js]
        end

        self.response_body = json
      end
    end
  end
end