Rails 3.1 fields_for 渲染几个字段并停止

发布于 2024-12-04 19:00:47 字数 1605 浏览 4 评论 0原文

在生产环境中使用 Phusion Passanger + Nginx 托管我的应用程序时,我遇到 fields_for 无法正确渲染大量字段的情况。

示例:

members_controller.rb:

class MembersController << ApplicationController

  def new
    @member = Member.new

    # There are 200 or so groups in the database.
    current_client.groups.active.each do |group|
      @member.affiliation.build(:group => group)
    end
  end
end

new.html.haml:

= form_for @member do |f|
  = f.text_field :name
  = f.text_field :phone
  = f.fields_for :affiliations do |affiliation_form|
   .group_field
      = affiliation_form.hidden_field :group_id
      = affiliation_form.label :_destroy, affiliation_form.object.group.name
      = affiliation_form.check_box :_destroy, { }, "0", "1"

到目前为止一切顺利,在开发中这将按照我的需要正确返回所有字段。在生产服务器上部署应用程序时(相同的 ruby​​ 1.9.2p180)。 HTML 不完整,最后一个 *.group_field* 呈现的 200 个字段中大约有 30-50 个字段不存在或存在一些元素(每次都有不同的结果)。

倒数第二个组字段:

<div class="group_field">
  <input id="..." name="..." type="hidden" value="48"> 
  <label for="...">...</label>
  <input name="..." type="hidden" value="1">
  <input id="..." name="..." type="checkbox" value="1"> 
</div>

最后一个组字段:

<div class="group_field">
  <input id="..." name="..." type="hidden" value="49">
  <label for="...">...</label>
</div>

日志不会产生任何错误,因此我无法找出错误/问题所在的位置。我也在生产环境中尝试过相同的形式,仅提供 20 个左右的组,效果非常好。 谁能帮我找出这个非常奇怪的错误吗?

Whilst in Production environment hosting my application with Phusion Passanger + Nginx I'm experiencing fields_for not being able to properly render a huge amount of fields properly.

Example:

members_controller.rb:

class MembersController << ApplicationController

  def new
    @member = Member.new

    # There are 200 or so groups in the database.
    current_client.groups.active.each do |group|
      @member.affiliation.build(:group => group)
    end
  end
end

new.html.haml:

= form_for @member do |f|
  = f.text_field :name
  = f.text_field :phone
  = f.fields_for :affiliations do |affiliation_form|
   .group_field
      = affiliation_form.hidden_field :group_id
      = affiliation_form.label :_destroy, affiliation_form.object.group.name
      = affiliation_form.check_box :_destroy, { }, "0", "1"

So far so good, in development this would return all the fields properly as I want them. When deploying the application on the production server (same ruby 1.9.2p180). The HTML is incomplete, having roughly 30-50 or so of the 200 fields rendered with the last *.group_field* having no or some elements present (different results every time).

Second last group field:

<div class="group_field">
  <input id="..." name="..." type="hidden" value="48"> 
  <label for="...">...</label>
  <input name="..." type="hidden" value="1">
  <input id="..." name="..." type="checkbox" value="1"> 
</div>

Last group field:

<div class="group_field">
  <input id="..." name="..." type="hidden" value="49">
  <label for="...">...</label>
</div>

Log yields no errors what so ever, so I haven't been able to find out where the bug/issue resides. I have also tried the same form in production environment only supplying 20 or so groups which works perfectly fine.
Can anyone help me track down this very strange bug?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独难免 2024-12-11 19:00:47

我几乎可以保证这是由于 Rails 3.1 引入了 HTTP 流。尽管该功能具有明显的选择性加入性质,但它似乎会导致许多问题,可能是由于 ActionView 的输出缓冲设施发生了变化,而像 fields_for 这样的帮助程序充分利用了这些设施。

目前,主要由于这一变化,nginx 和乘客对 Rails 3.1 的支持充其量是不稳定的。您会发现 其他类似的问题,最终切换到 UnicornThin 或类似的东西并从 nginx 进行代理。

I can almost guarantee this is due to Rails 3.1 introducing HTTP streaming. Despite the apparent opt-in nature of the feature, it seems to be causing many problems possibly due to the changes to ActionView's output buffering facilities of which helpers like fields_for take great advantage.

At the moment and mainly due to this change, nginx and passenger support for Rails 3.1 is flaky at best. You'll find other, similar questions which end with switching to Unicorn, Thin or something similar and proxying from nginx.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文