Re: Creating Many Models in One Form
Sure that will work, but it's when it comes to adding a new field based on that index, it gets me lost.
On the build method I used the following.
<%= render :partial => 'add_image_link', :locals => { :index => @property.property_images.size } %>_add_image_link.rhtml
<div id="add_image_link">
<%= link_to_remote 'Add Another Image', :loading => "$('add_image_link').hide", :url => { :action => 'add_image', :index => index } %>
</div>
add_image.rjs
page.insert_html :bottom, :property_images, :partial => 'image_fields',
:locals => { :property_image => @property_image, :index => params[:index] }page.replace :add_image_link, :partial => 'add_image_link', :locals => { :index => (params[:index].to_i + 1) }
Just not sure how to get this working on this new way, as there is nothing to loop through and I can't use fields_for
Now I'm a bit lost, sorry :)
Edit
_image_fields.rhtml
<div id="property_image_<%= index %>">
<% fields_for "property_images[#{index}]", property_image do |f| %>
<p>
<%= f.file_field :uploaded_data %>
<%= f.text_field :caption %>
<%= link_to_remote 'remove', :url => { :action => 'remove_image', :index => index } %>
</p>
<% end %>
</div>
Last edited by stevepsharpe (2007-04-06 19:03:44)