Created
June 8, 2013 07:30
-
-
Save giladmanor/5734411 to your computer and use it in GitHub Desktop.
Angular | Rails JSONP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myapp.component', ['ngResource']).factory('MyService', function($resource) { | |
return $resource('http://giladmanor.com\\:3000/t/t', {alt: 'json', callback: 'JSON_CALLBACK'}, | |
{ 'send': { method: 'JSONP'}}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiController < ActionController::Base | |
after_filter :callback_wrapper | |
def send | |
render :json=>{:status=>"ok"} | |
end | |
private | |
def callback_wrapper | |
unless params[:callback].nil? | |
response.body = "#{params[:callback]}(#{response.body});" | |
logger.debug "CALLBACK: \n\n #{response.body.inspect}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment