Post method to custom action

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.

Grayson Piercee 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

Grayson Piercee 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?

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 to use the right verb.

link_to sort_foos_path, :method=>:post

HTH, AndyV