How to set access-control-allow-origin in webrick under rails?
Rails 4 (http://edgeguides.rubyonrails.org/security.html#default-headers)
In config/application.rb:
config.action_dispatch.default_headers.merge!({ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Request-Method' => '*'})
If you're on Rails 2 just add this to your application contoller.
before_filter :set_accessdef set_access @response.headers["Access-Control-Allow-Origin"] = "*"end
Obviously changing "*"
to something a little less open would be a good idea.
Rails 3.1
class ApplicationController < ActionController::Base protect_from_forgery after_filter :set_access_control_headers def set_access_control_headers headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Request-Method'] = '*' endend