Hello together,
I developed a file upload in my application like this (files uploaded
belong to a project):
project_controller.rb:
----------------------
def upload_attachment
project = Project.find(@params[:id])
begin
project.attachments.create(params[:attachment])
rescue
flash[:attachment_error] = "Error at Upload"
end
redirect_to :action => "edit_project", :id => project
end
attachment_model:
-----------------
def attachment=(attachment_field)
self.name = base_part_of(attachment_field.original_filename)
self.content_type = attachment_field.content_type.chomp
self.data = attachment_field.read
end
def base_part_of file_name
name = File.basename(file_name)
name.gsub(/[^\w._-]/, '''')
end
edit_project.rhtml:
-------------------
<%= form_tag({:action => ''upload_attachment'', :id =>
@project},
:multipart => true ) %>
<input id="project_id" name="project[id]"
type="hidden" value="<%=
@project.id %>" />
Title: <%= text_field("attachment","title") %> <%=
file_field("attachment","attachment") %><br/>
<%= submit_tag ("Upload") %>
<%= end_form_tag %>
Now the PROBLEM: What have I to write to get a multiple file upload, for
example 5 files with one click on the Upload-Button. Is there anyone who
knows something?
Thank you very much!
My english is not the best, but I hope everything is understandable - if
not, please ask.
--
Posted via http://www.ruby-forum.com/.