Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top