【问题标题】:redirect_to after AJAX post stops working on remote machineAJAX post 停止在远程机器上工作后的 redirect_to
【发布时间】:2016-10-06 18:40:08
【问题描述】:

我有一个由 AJAX 调用的“创建”操作。这然后重定向到另一个动作。在我的本地机器上,一切正常。以下是我本地机器上的日志文件:

Started POST "/tasks" for 127.0.0.1 at 2016-10-06 20:08:44 +0200
Processing by TasksController#create as JS

Started GET "/roles/refresh_blank_page?cursor=3988&focus=true" for 127.0.0.1 at 2016-10-06 20:08:44 +0200
Processing by RolesController#refresh_blank_page as JS

但在远程机器上,在开发或生产中,它与“ActionController::UnknownFormat”中断。格式突然好像是 HTML,你可以在日志中看到:

Started POST "/tasks" for 88.217.180.75 at 2016-10-06 20:13:00 +0200
Processing by TasksController#create as JS

Started GET "/roles/refresh_blank_page?cursor=3981&focus=true" for 88.217.180.75 at 2016-10-06 20:13:02 +0200
Processing by RolesController#refresh_blank_page as HTML

这是我的行动:

def create
  (...)
  redirect_to roles_refresh_blank_page_path(focus: true, cursor: @task.id)
end


def refresh_blank_page
  (...)
  respond_to do |format|
    format.js { render :file => "/roles/refresh_blank_page.js.erb" }
  end
end

我在这里阅读了很多帖子并在重定向中添加了“格式:'js'”(也尝试了“remote:true”)

redirect_to roles_refresh_blank_page_path(focus: true, cursor: @task.id, format:'js')

在我现在看到的日志中:

Started GET "/roles/refresh_blank_page.js?cursor=3983&focus=true" for 88.217.180.75 at 2016-10-06 20:19:12 +0200
Processing by RolesController#refresh_blank_page as JS

但这现在会产生“ActionController::InvalidCrossOriginRequest in RolesController#refresh_blank_page”

我比较了本地机器和远程机器上的 gem。远程机器上的一些 gem 有更高的版本号。在这两种情况下,我都在运行 rails 4.1.8 和 ruby​​ 2.1.5p273。

感谢您的帮助, 罗恩

【问题讨论】:

    标签: ruby-on-rails ajax redirect


    【解决方案1】:

    我通过使用 bundle package 将我所有的开发 gem 打包到供应商/缓存中解决了这个问题。现在它可以在远程机器上运行。

    参见。 Whats the difference between bundle install --deployment and bundle pack

    【讨论】:

      猜你喜欢
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 2019-01-20
      • 2013-11-05
      • 2014-07-10
      • 1970-01-01
      • 1970-01-01
      • 2023-02-19
      相关资源
      最近更新 更多