Skip to content

Commit f45fddc

Browse files
committed
added support for jsonp callbacks
1 parent 96d9660 commit f45fddc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/acts_as_api/config.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module Config
1313
# to get added an additional root node
1414
# with the name of the model.
1515
ADD_ROOT_NODE_FOR = [:json]
16+
17+
ALLOW_JSONP_CALLBACK = false
1618

1719
# The default name of a root node of a response
1820
# if no root paramter is passed in render_for_api
@@ -24,11 +26,14 @@ module Config
2426
mattr_accessor :dasherize_for
2527
mattr_accessor :add_root_node_for
2628
mattr_accessor :default_root
29+
mattr_accessor :allow_jsonp_callback
2730

2831
@@accepted_api_formats = ACCEPTED_API_FORMATS
2932
@@dasherize_for = DASHERIZE_FOR
3033
@@add_root_node_for = ADD_ROOT_NODE_FOR
3134
@@default_root = DEFAULT_ROOT
35+
@@allow_jsonp_callback = ALLOW_JSONP_CALLBACK
36+
3237

3338
end
3439

lib/acts_as_api/rendering.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def render_for_api(api_template, render_options)
6767

6868
# create the Hash as response
6969
output_params[api_format] = api_response
70+
71+
output_params[:callback] = params[:callback] if ActsAsApi::Config.allow_jsonp_callback && params[:callback]
7072

7173
render output_params
7274

0 commit comments

Comments
 (0)