Forms blank when rendering a partial when using a collection of objects. Help!

Posted by dustmoo on Stack Overflow See other posts from Stack Overflow or by dustmoo
Published on 2010-06-07T18:51:35Z Indexed on 2010/06/07 18:52 UTC
Read the original article Hit count: 155

Filed under:
|
|

Alright, I know my title is a little obscure but it best describes the problem I am having.

Essentially, I have a list of users, and want to be able to edit their information in-line using AJAX.

Since the users are showing up in rows, I am using a partial to render the data and the forms (which will be hidden initially by the ajax), however, when the rows are rendered currently only the last item has it's form's fields populated.

I suspect this has something to do with the fact that all the form fields have the same id's and it is confusing the DOM. But I don't know how to make sure the id's are unique.

Here is a small example:

In my view:

<%= render :partial => 'shared/user', :collection => @users %>

My partial (broke down to just the form) note that I am using the local variable "user"

<% form_for user, :html => {:multipart => true} do |f| -%>
<%= f.label :name, "Name*" %>
<%= f.text_field :title, :class => "input" %>
<%= f.label :Address, "Address" %>
<%= f.text_field :address, :class => "input" %>
<%= f.label :description, "Description*" %>
<%= f.text_area :description, :class => "input" %>
<% end -%>

When the html is rendered each form has a unique id (for the id of the user) but the elements themselves all have the same id, and only the last user form is actually getting populated with values.

Does anyone have any ideas?? :)

Thanks in advance!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about forms