In your view:
<label for="files[]">File </label>
<%= file_field_tag ''files[]'' %>
And id suggest putting it in a partial and then getting an ajax link
that renders one each time.So assuming, you put the above lines in a
partial called _file_form.html.erb then you want something like:
<div id="file_forms"></div>
<%= link_to_remote( "Add another file
:update => "file_forms",
:url => { :action => :add_file_form },
:position => "bottom" ) %>
Which calls a controller method calles add_file_form wich is
basically:
def add_file_form
render(:partial => ''file_form'')
end
Ajax aside, the function that hadles the params should look something
like:
def include_files
params[:files].each_with_index do |file, index|
model = ModelName.new( :uploaded_data => file )
if model.valid?
# save or attach to other or do whatever you need
else
# your data was not valid. so redirect, flash, whatever
end
end
end
please nopte that i am using the plugin attachment_fu to upload and
handle binaries. and my example is used with images, so i have to
validate the files size and type before i save it.
hope it helps
On Jun 24, 11:35 am, Thorsten Müller
<thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org>
wrote:> You must give each of them a unique name and then you''ll get
> a param for each of them. Otherwise it won''t work.
>
> If you need this for a real world app you may consider
> using swfupload instead, since it''s more comfortable for
> the user (but more difficult to implement)
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@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
-~----------~----~----~----~------~----~------~--~---