Forms with has_many, using fields_for + Paperclip

I know rails has super easy ways of doing this but I’m not sure
exactly how.

I have one model “LineItems” which has_many :order_attachments.
OrderAttachment is using paperclip, but I’m thinking this would be the
same regardless. I’m wondering. In my LineItem “new” view how can I
add one (or more) OrderAttachment within the same form.

Lets say LineItem has an “order_name” attribute. And each
OrderAttachment has a “attachment” (which is currently a paperclip
attachment). I’m doing the following, and the image gets uploaded in
the log, but never saves to OrderAttachment. Any ideas? Is this the
correct way to do it? Also (if anyone knows off hand) is there a quick
way to expand this so the user can upload as many attachments as they
want?

<%= form_for(@line_item, :html => { :multipart => true }) do |f| %>
<%= fields_for :order_attachments do |attachment_form| %>
<%= attachment_form.file_field :attachment %>
<% end %>
<%= f.text_field :item_name %>
<%= f.submit %>
<% end %>

Found a solution here:
http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/

I had to add this to my LineItem new action:

1.times {@line_item.order_attachments.build}

Also I was using fields_for instead of f.fields_for

Now I just need to allow users to upload more if they want. Anyone
know of a simple JS plugin to add more fields_for items? I suppose I
could write one but I would think there’s one out there…

I’m not sure, but maybe this railcast could help you:

http://railscasts.com/episodes/74-complex-forms-part-2

#74 Complex Forms Part 2
Oct 08, 2007 | 8 minutes | Forms http://railscasts.com/?tag_id=15,
Ajaxhttp://railscasts.com/?tag_id=11,
Views http://railscasts.com/?tag_id=4
See how to use Javascript and RJS to add and remove form fields
dynamically.
This episode will build upon the previous episode allowing you to create
any
number of tasks in one form the same time a project is created.