title: Can't get rack-cors working in rails application
body: <p>I wanted to implement CORS in my rails application, so I googled <a href="https://github.com/cyu/rack-cors">rack-cors</a> gem for it. And I did everything as was said in README, that is updated Gemfile accordingly and updated <code>application.rb</code> like this: <br></p>
  
  <pre><code>module YourApp
    class Application &lt; Rails::Application
  
      # ...
  
      config.middleware.use Rack::Cors do
        allow do
          origins '*'
          resource '*', :headers =&gt; :any, :methods =&gt; [:get, :post, :options]
        end
      end
  
    end
  end
  </code></pre>
  
  <p>But it didn't work. No matter what I did, in the browser console I kept getting message:<br/>
  <code>XMLHttpRequest cannot load https://somewebsite.com. Origin http://0.0.0.0:3000 is not allowed by Access-Control-Allow-Origin.</code><br></p>
  
  <p>After reading this <a href="http://www.dougwaltman.com/blog/getting-cors-working-in-ruby-on-rails">blogpost</a> and <a href="https://github.com/cyu/rack-cors/issues/23">issue</a> on github, I realized that maybe position of rack-cors middleware in the middleware stack matters. So I did as was told in the github issue:</p>
  
  <pre><code>module YourApp
    class Application &lt; Rails::Application
  
      # ...
  
      config.middleware.insert 0, Rack::Cors do
        allow do
          origins '*'
          resource '*', :headers =&gt; :any, :methods =&gt; [:get, :post, :options]
        end
      end
  
    end
  end
  </code></pre>
  
  <p>After that, when I run <code>rake middleware</code> rack-cors is really at the top of the stack.<br>
  But It still just simply won't work. I keep getting the same error. Anyone, please help.</p>