# Post method map.resources

**URL:** <https://www.ruby-forum.com/t/post-method-map-resources/130710>\
**Category:** Rails\
**Created:** [March 2, 2008, 9:46am UTC](https://www.ruby-forum.com/t/post-method-map-resources/130710 "2008-03-02T09:46:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grayson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@grayson](https://www.ruby-forum.com/u/grayson)\
**Post date:** [March 2, 2008, 9:46am UTC](https://www.ruby-forum.com/t/post-method-map-resources/130710/1 "2008-03-02T09:46:14Z")

</div>

Sorry if this is a really basic question but I can’t seem to add my own  
action that works through a post method. I’ve tried :new, :create,  
:collection, :member, etc without any success it seems to automatically  
take you to create or show as soon as it senses a post (get mappings  
work just fine!)

TIA

---

<div class="post-metadata">

**Author:** ![grayson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@grayson](https://www.ruby-forum.com/u/grayson)\
**Post date:** [March 2, 2008, 10:11am UTC](https://www.ruby-forum.com/t/post-method-map-resources/130710/2 "2008-03-02T10:11:31Z")

</div>

Taken from…  
[http://api.rubyonrails.org/classes/ActionController/Routing.html](http://api.rubyonrails.org/classes/ActionController/Routing.html) \>\>  
Route  
conditions

With conditions you can define restrictions on routes. Currently the  
only  
valid condition is :method.

- :method - Allows you to specify which method can access the route.  
Possible values are :post, :get, :put, :delete and :any. The default  
value is :any, :any means that any method can access the route.

Example:

map.connect ‘post/:id’, :controller =\> ‘posts’, :action =\> ‘show’,  
:conditions =\> { :method =\> :get }  
map.connect ‘post/:id’, :controller =\> ‘posts’, :action =\>  
‘create\_comment’,  
:conditions =\> { :method =\> :post }

Now, if you POST to /posts/:id, it will route to the create\_comment  
action.  
A GET on the same URL will route to the show action.  
or if you are using a resource… from  
[http://api.rubyonrails.org/classes/ActionController/Resources.html](http://api.rubyonrails.org/classes/ActionController/Resources.html)

map.resources :messages, :collection =\> { :rss =\> :get }

# → GET /messages/rss (maps to the #rss action)

# also adds a named route called “rss\_messages”

map.resources :messages, :member =\> { :mark =\> :post }

# → POST /messages/1/mark (maps to the #mark action)

# also adds a named route called “mark\_message”

On Sun, Mar 2, 2008 at 1:46 AM, Grayson P. \<  
removed\_email\_address@domain.invalid\> wrote:

> >

–  
-Robert Ferney ( Kolbe 4357 Demonstrator / Myer Brigs INTJ )
