LoginSignup
25
19

More than 5 years have passed since last update.

Rails(Grape)でAPIを作成する備忘録2

Last updated at Posted at 2015-03-14

前回作ったAPIのクロスドメインアクセスを許可させてみた

やったこと

rack-corsを追加

Gemfile
gem 'rack-cors', :require => 'rack/cors'

config/applicationを編集

config/application.rb
module APISample
  class Application < Rails::Application
    ... 
    config.middleware.insert_before ActionDispatch::Static, Rack::Cors do
      allow do
        origins '*'
        resource '*', :headers => :any, :methods => [:get, :post, :options, :patch, :delete]
      end
    end
    ...
  end
end

これだけで他ドメインからアクセスできるようになりました

参考
http://qiita.com/hkusu/items/b34f684b49751d9c9abd

25
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
19