0

I'm having trouble with a route that seems to be right in the console but gives me a routing error when I use it in the server. The case is similar to the "edit" and "update" pair. Calling GET 'messages/25/followup' should route to messages#followup, while the same URL with POST should route to messages#followup_send. In my routes.rb file I have

get "messages/:id/followup", :to => "messages#followup"
match "messages/:id/followup", :to => "messages#followup_send", :via => :post

Displaying the routes gives

ruby-1.9.2-p0 :092 > puts fu
GET  /messages/:id/followup(.:format)  {:controller=>"messages", :action=>"followup"}
POST /messages/:id/followup(.:format)  {:controller=>"messages", :action=>"followup_send"}

Testing in the console gives

ruby-1.9.2-p0 :088 > r.recognize_path "/messages/54/followup", :method=>'POST'
=> {:controller=>"messages", :action=>"followup_send", :id=>"54"} 

The code in the form is

<form id="edit_message_42" class="edit_message" method="post" action="/messages/42/followup?method=post" accept-charset="UTF-8">
...
<input type="submit" value="Send" name="commit">

However, if I click on the button I get in the log

Started POST "/messages/42/followup?method=post" for 127.0.0.1 at 2012-06-27 13:54:48 +0100
ActionController::RoutingError (No route matches "/messages/42/followup")

The same thing happens if I enter the URL manually (including the "method=post'). I will just get around this for now by using a separate name (e.g. /messages/42/send_followup) rather than relying on the GET-POST distinction, but I would like to understand what is going on here.

Thanks for any ideas.

Mike Blyth
  • 4,158
  • 4
  • 30
  • 41
  • Have you tried removing the query string from the end of the form action? Since the form action is POST, you shouldn't need any query parameters to transmit information. –  Jun 27 '12 at 13:13
  • Good point. I used "form_for @record, :url => { :action => "followup_send", :method=>:post }" because I didn't realize or remember that Rails would automatically figure that out. Unfortunately, fixing that didn't help. Furthermore, changing to a different name in the URL hasn't worked either. I'll try an ordinary get. – Mike Blyth Jun 27 '12 at 13:22
  • Works when I change the route from "post 'messages/:id/followup_send', :to => 'messages#followup_send' to "match 'messages/:id/followup_send', :to => 'messages#followup_send'. I still don't know why the POST version doesn't work. – Mike Blyth Jun 27 '12 at 13:28

0 Answers0