Forum: Ruby on Rails RJS and remote forms

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B554bcde846e4497eeffffc1399d3b09?d=identicon&s=25 Benjamin Stiglitz (benstiglitz)
on 2006-04-05 07:15
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:
  <tr>
  <% remote_form_for :guest, guest, :url => { :action => 'create_guest'
} do |f| %>
    <%= f.hidden_field :party_id %>
    <td><%= f.text_field :first_name %></td>
    <td><%= f.text_field :last_name %> <%= submit_tag %></td>
    <% end %>
  </tr>

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â?¦
E9fa5947081cf6b45f89a1f07f064418?d=identicon&s=25 Dj T@l (Guest)
on 2006-04-05 07:28
Benjamin Stiglitz 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:
>   <tr>
>   <% remote_form_for :guest, guest, :url => { :action => 'create_guest'
> } do |f| %>
>     <%= f.hidden_field :party_id %>
>     <td><%= f.text_field :first_name %></td>
>     <td><%= f.text_field :last_name %> <%= submit_tag %></td>
>     <% end %>
>   </tr>

HTH Dj T@l
B554bcde846e4497eeffffc1399d3b09?d=identicon&s=25 Benjamin Stiglitz (benstiglitz)
on 2006-04-05 07:42
>>   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
This topic is locked and can not be replied to.