6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/restful_jsonp/jsonp_responder.rb', line 6
def display(resource, given_options = {})
if format == :json && controller.params[:callback] && !controller.request.xhr?
jsonp_options = {}
status = given_options[:status] || options[:status]
if (resource.respond_to?(:errors) && !resource.errors.empty?) ||
(status && ![:ok, :created].include?(status))
jsonp_options[:status] = :accepted resource = {
:error => {
:status => status,
:data => resource.to_json
}
}
end
jsonp_options[format] = resource
jsonp_options[:callback] = controller.params[:callback]
render options.merge!(given_options).merge!(jsonp_options)
else
super
end
end
|