I\'m creating a set of services using Rails 4, which I am consuming with a JavaScript browser application. Cross-origin GETS are working fine, but my POSTs are failing the p
Working on Rails 3.2.11.
I put
match '*path', :controller => 'application', :action => 'handle_options_request', :constraints => {:method => 'OPTIONS'}
in my routes.rb file. The key was to put it as top priority (on top of the routes.rb file). Created that action so that it is publicly available:
def handle_options_request
head(:ok) if request.request_method == "OPTIONS"
end
And a filter in application controller:
after_filter :set_access_control_headers
def set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
end