How to set access-control-allow-origin in webrick under rails?

后端 未结 6 686
广开言路
广开言路 2020-12-02 13:08

I have written a small rails app to serve up content to another site via xmlhttprequests that will be operating from another domain (it will not be possible to get them runn

6条回答
  •  情歌与酒
    2020-12-02 13:56

    If you're on Rails 2 just add this to your application contoller.

    before_filter :set_access
    
    def set_access
      @response.headers["Access-Control-Allow-Origin"] = "*"
    end
    

    Obviously changing "*" to something a little less open would be a good idea.

提交回复
热议问题