Rails remote form_tag在标头中返回额外的内容类型

时间:2019-06-30 16:29:03

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

我将启动方法从rails s更改为bundle exec puma,以便puma可以读取其config/puma.rb配置文件,现在某些浏览器的远程form_tags已损坏(javascript浏览器忽略了响应)。

我检查了标头,发现响应现在包括两个内容类型的标头:

content-type: text/html; charset=windows-1251
content-type: text/javascript; charset=utf-8

如果我改为通过rails s启动服务器,则它将按预期运行,并且仅显示一种内容类型:

content-type: text/javascript; charset=utf-8

似乎只有form_tagbutton_to类型受到影响。例如,远程link_to类型仍然可以正常工作。

有什么解决方法吗?

Ruby 2.3.3,Rails 4.2.11,Puma 3.12.1


remote_test_controller.rb:

class RemoteTestController < ApplicationController
  def index
  end

  def update
    @result = 'Some text from remote'
  end
end

index.html.erb:

<h1>RemoteTest#index</h1>
<%= form_tag(remote_test_update_path, remote: true) do %>
  <button id="update-btn" type="submit">Update</button>
<% end %>
<div id="update-test"></div>

update.js.erb:

$('#update-test').html('<%= @result %>')

0 个答案:

没有答案
相关问题