Skip to content

Instantly share code, notes, and snippets.

@giladmanor
Created June 8, 2013 07:30
Show Gist options
  • Save giladmanor/5734411 to your computer and use it in GitHub Desktop.
Save giladmanor/5734411 to your computer and use it in GitHub Desktop.
Angular | Rails JSONP
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'}});
});
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