RJS and remote forms

I’ve run into what I think is a browser bug related to using
remote_forms pushed in an RJS update.

In my controller, I have an action that creates a new model and returns
a form for one of its children:

def create_party
party = Party.create
render :update do |page|
page.insert_html :top, ‘party-list’, :partial => ‘party_header’,
:locals => { :party => party }
page.insert_html :after, “party-#{party.id}”, :partial =>
‘guest_form’, :locals => { :guest => party.guests.build }
end
end

_guest_form.rhtml is:

<% remote_form_for :guest, guest, :url => { :action => 'create_guest' } do |f| %> <%= f.hidden_field :party_id %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= submit_tag %> <% end %>

Unfortunately, when the form is submitted, params[] contains only the
party_id, and not the other values Iâ??ve typed in (not even a blank value
for the key). Itâ??s either a browser problem, due to issues with
programmatically-generated content, or something strange in
Form.serialize.

Has anyone else run into this issue? I donâ??t think Iâ??m doing anything
particularly boneheaded hereâ?¦

Benjamin S. wrote:

def create_party
party = Party.create
render :update do |page|
page.insert_html :top, ‘party-list’, :partial => ‘party_header’,
:locals => { :party => party }
page.insert_html :after, “party-#{party.id}”, :partial =>
‘guest_form’, :locals => { :guest => party.guests.build }
end
end

Use page.insert_html :top, ‘party-list’, :partial => ‘party_header’,
:object => party instead
And for guest
page.insert_html :after, “party-#{party.id}”, :partial => ‘guest_form’,
:object => party.guests.build

_guest_form.rhtml is:

<% remote_form_for :guest, guest, :url => { :action => 'create_guest' } do |f| %> <%= f.hidden_field :party_id %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= submit_tag %> <% end %>

HTH Dj T@l

def create_party
party = Party.create
render :update do |page|
page.insert_html :top, ‘party-list’, :partial => ‘party_header’,
:locals => { :party => party }
page.insert_html :after, “party-#{party.id}”, :partial =>
‘guest_form’, :locals => { :guest => party.guests.build }
end
end

Use page.insert_html :top, ‘party-list’, :partial => ‘party_header’,
:object => party instead
And for guest
page.insert_html :after, “party-#{party.id}”, :partial => ‘guest_form’,
:object => party.guests.build

AFAIK, :locals has replaced the old :object spec. In any case, the
change above breaks the party_id field.

The issue is not that the rendered form is not displaying properlyâ??itâ??s
that submitting that form omits field values.

-Ben