# How to add a route to the method 'options' for each controller?

**URL:** <https://www.ruby-forum.com/t/how-to-add-a-route-to-the-method-options-for-each-controller/181434>\
**Category:** Rails\
**Created:** [January 12, 2010, 12:54am UTC](https://www.ruby-forum.com/t/how-to-add-a-route-to-the-method-options-for-each-controller/181434 "2010-01-12T00:54:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJ\_ONeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@AJ\_ONeal](https://www.ruby-forum.com/u/AJ_ONeal)\
**Post date:** [January 12, 2010, 12:54am UTC](https://www.ruby-forum.com/t/how-to-add-a-route-to-the-method-options-for-each-controller/181434/1 "2010-01-12T00:54:02Z")

</div>

Currently I’m mapping all of my controllers to use the same set of http  
options in a controller called option

map.connect ‘\*path’,  
:controller =\> ‘option’,  
:action =\> ‘options’,  
:conditions =\> {:method =\> :options}

But I would like to know how to do something along these lines

map.connect ‘:controller\*’,  
:action =\> ‘options’,  
:conditions =\> {:method =\> :options}

Which currently yields  
Allow: GET, POST, PUT, DELETE  
Status: 501 Not Implemented

The goal is that whenever a client application pre-flights a  
cross-origin  
request (CORS) the controller will issue the same options regardless of  
the  
action, but contingent upon the controller.

This is the options method which I would like to be able to control on a  
per-controller basis:  
def options  
render :nothing =\> true, :status =\> 204  
response.headers[‘Access-Control-Allow-Origin’] = ‘\*’  
response.headers[‘Access-Control-Allow-Methods’] = ‘POST, GET,  
PUT,  
DELETE, OPTIONS’  
response.headers[‘Access-Control-Allow-Credentials’] = ‘true’  
response.headers[‘Access-Control-Max-Age’] = ‘86400’  
response.headers[‘Access-Control-Allow-Headers’] =  
‘X-Requested-With,  
X-HTTP-Method-Override, Content-Type, Accept’  
end

AJ ONeal

---

<div class="post-metadata">

**Author:** ![AJ\_ONeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@AJ\_ONeal](https://www.ruby-forum.com/u/AJ_ONeal)\
**Post date:** [January 15, 2010, 8:48pm UTC](https://www.ruby-forum.com/t/how-to-add-a-route-to-the-method-options-for-each-controller/181434/2 "2010-01-15T20:48:46Z")

</div>

I found the answer to my question and here’s a link to the other  
thread:

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/29c8e6f4175b1676](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/29c8e6f4175b1676)
