Rails:redirect_to动作后的次要帖子请求不稳定

时间:2015-03-27 15:57:23

标签: ruby-on-rails ruby-on-rails-4

我偶尔遇到问题,在重定向到索引之后似乎存在辅助发布请求。

以下行为发生在95%的时间:

Started POST "/update_workorder" for 172.16.92.73 at 2015-03-27 08:13:57 -0700
I, [2015-03-27T08:13:57.709649 #11686]  INFO -- : Processing by R5EventsController#update_workorder as HTML
I, [2015-03-27T08:13:57.710186 #11686]  INFO -- :   Parameters: {"utf8"=>"✓", "authenticity_token"=>"CFuQjQ6jpJCTMqAjLhz1ZBLXdfIB8lnkjsJOO1f857w=", "stuff"="data"}
I, [2015-03-27T08:13:59.344661 #11686]  INFO -- :   Rendered pm_mailer/default_email.html.haml (9.0ms)
I, [2015-03-27T08:14:00.024827 #11686]  INFO -- : 
Sent mail to people@email.com (534.2ms)
I, [2015-03-27T08:14:00.028079 #11686]  INFO -- : Redirected to http://eambeweb/r5_events
I, [2015-03-27T08:14:00.028283 #11686]  INFO -- : Completed 302 Found in 2318ms (ActiveRecord: 1203.3ms)
I, [2015-03-27T08:14:00.297247 #11686]  INFO -- : Started GET "/r5_events" for 172.16.92.73 at 2015-03-27 08:14:00 -0700
I, [2015-03-27T08:14:00.298461 #11686]  INFO -- : Processing by R5EventsController#index as HTML
I, [2015-03-27T08:14:00.469535 #11686]  INFO -- :   Rendered r5_events/index.html.haml within layouts/application (163.0ms)
I, [2015-03-27T08:14:00.476018 #11686]  INFO -- : Completed 200 OK in 177ms (Views: 72.5ms | ActiveRecord: 101.5ms)

但有时会有一些如何,有时候开始GET,它会启动一个POST:

Started POST "/update_workorder" for 172.16.92.73 at 2015-03-27 08:17:35 -0700
I, [2015-03-27T08:17:35.176066 #11702]  INFO -- : Processing by R5EventsController#update_workorder as HTML
I, [2015-03-27T08:17:35.176583 #11702]  INFO -- :   Parameters: {"utf8"=>"✓", "authenticity_token"=>"CFuQjQ6jpJCTMqAjLhz1ZBLXdfIB8lnkjsJOO1f857w=", "stuff"="data"}
I, [2015-03-27T08:17:35.981182 #11702]  INFO -- :   Rendered pm_mailer/default_email.html.haml (9.4ms)
I, [2015-03-27T08:17:36.565325 #11702]  INFO -- : 
Sent mail to people@email.com (445.9ms)
I, [2015-03-27T08:17:36.568528 #11702]  INFO -- : Redirected to http://eambeweb/r5_events
I, [2015-03-27T08:17:36.568737 #11702]  INFO -- : Completed 302 Found in 1392ms (ActiveRecord: 448.3ms)
I, [2015-03-27T08:17:38.567563 #11702]  INFO -- : Started POST "/update_workorder" for 172.16.92.73 at 2015-03-27 08:17:38 -0700
I, [2015-03-27T08:17:38.569935 #11702]  INFO -- : Processing by R5EventsController#update_workorder as HTML
I, [2015-03-27T08:17:38.570403 #11702]  INFO -- :   Parameters: {"utf8"=>"✓", "authenticity_token"=>"CFuQjQ6jpJCTMqAjLhz1ZBLXdfIB8lnkjsJOO1f857w=", "stuff"="data"}
I, [2015-03-27T08:17:39.001262 #11702]  INFO -- :   Rendered pm_mailer/default_email.html.haml (7.7ms)
I, [2015-03-27T08:17:39.639698 #11702]  INFO -- : 
Sent mail to people@email.com (637.7ms)
I, [2015-03-27T08:17:39.640420 #11702]  INFO -- : Redirected to http://eambeweb/r5_events
I, [2015-03-27T08:17:39.640662 #11702]  INFO -- : Completed 302 Found in 1070ms (ActiveRecord: 414.4ms)
I, [2015-03-27T08:17:39.851618 #11702]  INFO -- : Started GET "/r5_events" for 172.16.92.73 at 2015-03-27 08:17:39 -0700
I, [2015-03-27T08:17:39.852857 #11702]  INFO -- : Processing by R5EventsController#index as HTML
I, [2015-03-27T08:17:40.091512 #11702]  INFO -- :   Rendered r5_events/index.html.haml within layouts/application (227.0ms)
I, [2015-03-27T08:17:40.098016 #11702]  INFO -- : Completed 200 OK in 245ms (Views: 70.1ms | ActiveRecord: 172.0ms)

我的update_workorder方法:

def update_workorder
    # .... horrifying amount of lines
    PmMailer.default_email(workorder["org"],workorder,assets,current_user,lines).deliver
    if workorder["priority"] != '0' and !workorder["priority"].nil?
      PmMailer.send_email_with_higher_priority(workorder["org"],workorder,assets,current_user).deliver
    end
    redirect_to action: "index"
end

我的表格没什么特别的:

= form_tag("/update_workorder", method: "post") do
  -# terrible terrible
  %br  
  .row-fluid
    .col-xs-12
      %br/
      %input{:type=>"button", :value=>"Back to My Workorders", :style=>"margin-bottom:10px;width:240px;height:50px;font-size:1.5em", :onClick =>"history.go(-1);return true;"}
      %input{:type=>"submit", :value=>"Save", :style=>"margin-bottom:10px;width:240px;height:50px;font-size:1.5em;margin-left:50px"}

1 个答案:

答案 0 :(得分:0)

Rob W.完全正确。问题不在于应用程序本身,而是用户使用后台和保存按钮。我做了四件事:

  • 根据Rob W.的建议,我改变了后退按钮的行为
  • 如果用户使用后退按钮
  • 来到此表单,我通过javascript添加了自动刷新功能
  • 我在提交
  • 后禁用了保存按钮
  • 我添加了一个近期交易的小历史记录,向用户显示该操作已经执行过。