# Post method to custom action

**URL:** <https://www.ruby-forum.com/t/post-method-to-custom-action/130727>\
**Category:** Rails\
**Created:** [March 2, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/post-method-to-custom-action/130727 "2008-03-02T17:46:31Z")\
**Posts on this page:** 4\
**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, 5:46pm UTC](https://www.ruby-forum.com/t/post-method-to-custom-action/130727/1 "2008-03-02T17:46:31Z")

</div>

I posted this question last night but it doesn’t seem to have made it to  
the group.

I’m wondering why I can’t get a post method to work for a custom action

I’ve tried

map.resources :foo, :collection =\> { :sort =\> :post}  
map.resources :foo, :new =\> { :sort =\> :post}  
map.resources :foo, :create =\> { :sort =\> :post}  
map.resources :foo, :member =\> { :sort =\> :post}

In all cases the post call seems to take me to either the create action  
or show.

Sorry if this is a really basic question but docs say you should be able  
to do :any and it’s not happening for me.

Thanks.

---

<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 3, 2008, 5:16am UTC](https://www.ruby-forum.com/t/post-method-to-custom-action/130727/2 "2008-03-03T05:16:35Z")

</div>

Grayson P. wrote:

> I posted this question last night but it doesn’t seem to have made it to  
> the group.
> 
> I’m wondering why I can’t get a post method to work for a custom action
> 
> I’ve tried
> 
> map.resources :foo, :collection =\> { :sort =\> :post}  
> map.resources :foo, :new =\> { :sort =\> :post}  
> map.resources :foo, :create =\> { :sort =\> :post}  
> map.resources :foo, :member =\> { :sort =\> :post}
> 
> In all cases the post call seems to take me to either the create action  
> or show.
> 
> Sorry if this is a really basic question but docs say you should be able  
> to do :any and it’s not happening for me.
> 
> Thanks.

When you mean it doesn’t work, do you mean that your method in the  
controller doesn’t get dispatched to?

In the future, when asking for help, please provide at least some  
details like the error message that you are getting, relevant log info,  
stack trace, etc, Using this information, we can provide further  
assistance…

ilan

---

<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 3, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/post-method-to-custom-action/130727/3 "2008-03-03T17:43:35Z")

</div>

Based on what you’ve posted, my guess is that you want to return a set  
of sorted foos. If that’s the case, the first form is correct – it’s  
an operation on the entire collection of foos. The form appears to be  
correct as well (action\_id =\> HTTP Verb).

The first question then is: did you restart your webrick/mongrel  
server? The routes file is only parsed when the server starts so you  
could have made the correct change and the server just did not know  
it.

Next, you may need to look at how you invoked the call to the server.  
Forms default to POST and links often use a GET. Rails provides  
a :method option as part of its helpers so you can force the postback  
to use the right verb.

link\_to sort\_foos\_path, :method=\>:post

HTH,  
AndyV

On Mar 2, 11:46 am, Grayson P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<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 3, 2008, 7:57am UTC](https://www.ruby-forum.com/t/post-method-to-custom-action/130727/4 "2008-03-03T07:57:52Z")

</div>

Grayson P. wrote:

> I’m wondering why I can’t get a post method to work for a custom action

Did you restart the application after changing your routes.rb file?
