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 %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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.. On Jul 27, 11:15 am, Brent <wejrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 %>-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Everaldo Gomes
2011-Jul-27 19:35 UTC
Re: Re: forms with has_many, using fields_for + Paperclip
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>, Ajax<http://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. On Wed, Jul 27, 2011 at 3:52 PM, Brent <wejrowski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.. > > > > On Jul 27, 11:15 am, Brent <wejrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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 %> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.