Ruby2.0, Rails4.0.2で確認 昨日のNode.jsでJSONP対応する方法に続いて、今回はRailsでJSONP対応する方法です。 通常のJSON通常のJSONを返す場合はrenderにオブジェクトを渡すとJSON形式で出力されます render json: { sample: 'this is test json' }出力結果は {"sample":"this is test json"}となります。 JSONPJSONPでレスポンスを返す場合はcallbackオプションを指定します render json: { sample: 'this is test json' }, callback: ERB::Util.html_escape(params[:callback])?callback=cbでアクセスした出力結果は cb({"sample":"this is tes
![[Rails]JSONP対応を簡単に行う方法](https://cdn-ak-scissors.b.st-hatena.com/image/square/1a64cc21309639f33304c4730f8ddaaf393eeaf8/height=288;version=1;width=512/https%3A%2F%2Fblog.hilotter.com%2Ffavicon%2Fogp.png)