Rails路由在控制台中工作,但在服务器上工作

时间:2012-06-27 13:00:05

标签: ruby-on-rails-3 routes rails-routing http-method

我遇到了一个似乎在控制台中正确的路由,但在我在服务器中使用它时出现了路由错误。该案例类似于“编辑”和“更新”对。调用GET'messages / 25 / followup'应该路由到消息#followup,而与POST相同的URL应该路由到消息#followup_send。在我的routes.rb文件中我有

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

显示路线

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"}

在控制台中进行测试

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

表单中的代码是

<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">

但是,如果我点击按钮,我会进入日志

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")

如果我手动输入URL(包括“method = post”),也会发生同样的事情。我现在通过使用一个单独的名称(例如/ messages / 42 / send_followup)来解决这个问题,而不是依赖于GET-POST区别,但我想了解这里发生了什么。

感谢任何想法。

0 个答案:

没有答案