Created
          March 25, 2013 14:08 
        
      - 
      
- 
        Save ckozus/5237351 to your computer and use it in GitHub Desktop. 
  
    
      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 RequestsController < ApplicationController | |
| def create | |
| if access_allowed? | |
| set_access_control_headers | |
| head :created | |
| else | |
| head :forbidden | |
| end | |
| end | |
| def options | |
| if access_allowed? | |
| set_access_control_headers | |
| head :ok | |
| else | |
| head :forbidden | |
| end | |
| end | |
| private | |
| def set_access_control_headers | |
| headers['Access-Control-Allow-Origin'] = request.env['HTTP_ORIGIN'] # '*' | |
| headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS' | |
| headers['Access-Control-Max-Age'] = '1000' | |
| headers['Access-Control-Allow-Headers'] = 'Content-Type' #'*, X-Requested-With' #'*, Origin, Content-Type, Accept, X-Requested-With, X-CSRF-Token' #'Authorization' | |
| headers['Content-Type'] = 'text/plain' | |
| headers['Access-Control-Allow-credentials'] = 'true' | |
| end | |
| end | 
  
    
      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
    
  
  
    
  | match '*request', :controller => 'requests', :action => 'options', :constraints => {:method => 'OPTIONS', :format => 'json'} | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment