yokomizor
yokomizor

Reputation: 1577

How to respond to OPTIONS HTTP Method in rails-api?

I'm using rails-api to build a public json api.

I would like to respond to OPTIONS HTTP Method to take advantages of Cross-Origin Resource Sharing.

http://www.w3.org/TR/cors/

I'm doing this:

headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'

It works, but some URLs does not support all HTTP methods. In those cases I'm lying.

I don't want to configure Access-Control-Allow-Methods for each URL.

Is there a way to respond Access-Control-Allow-Methods based on my routes?

Upvotes: 16

Views: 7790

Answers (1)

andrhamm
andrhamm

Reputation: 4411

check out the rack-cors gem, it allows you to configure it like a routes file

https://github.com/cyu/rack-cors

Upvotes: 11

Related Questions