Skip to content

Instantly share code, notes, and snippets.

@jsomara
Created July 10, 2014 14:53
Show Gist options
  • Save jsomara/eaa2bba40aeca26fcacc to your computer and use it in GitHub Desktop.
Save jsomara/eaa2bba40aeca26fcacc to your computer and use it in GitHub Desktop.
class Api::BaseController < ApplicationController
before_filter :authenticate_user!, :except => [:options]
before_filter :subscribed_user, :except => [:options]
...
def options
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
headers['Access-Control-Max-Age'] = '1000'
headers['Access-Control-Allow-Headers'] = 'X-Requested-With,Content-Type, Cache-Control, Accept, X-CSRF-Token, Authorization, X-XSRF-Token'
render :json => "", :content_type => "application/json"
end
end
# CORS Configuration
config.middleware.insert_before Warden::Manager, Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options, :delete, :put]
end
end
match "/*path" => "base#options", :via => :options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment