diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 08b5e0b81..a31b7ec55 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -340,16 +340,14 @@ class ProjectsController < ApplicationController render :action => "list_news", :layout => false if request.xhr? end - def add_file - if request.post? - # Save the attachment - if params[:attachment][:file].size > 0 - @attachment = @project.versions.find(params[:version_id]).attachments.build(params[:attachment]) - @attachment.author_id = self.logged_in_user.id if self.logged_in_user - if @attachment.save - flash[:notice] = l(:notice_successful_create) - redirect_to :controller => 'projects', :action => 'list_files', :id => @project - end + def add_file + @attachment = Attachment.new(params[:attachment]) + if request.post? and params[:attachment][:file].size > 0 + @attachment.container = @project.versions.find_by_id(params[:version_id]) + @attachment.author = logged_in_user + if @attachment.save + flash[:notice] = l(:notice_successful_create) + redirect_to :controller => 'projects', :action => 'list_files', :id => @project end end @versions = @project.versions diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 2e1e9b156..aca86cec5 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -21,7 +21,7 @@ class Attachment < ActiveRecord::Base belongs_to :container, :polymorphic => true belongs_to :author, :class_name => "User", :foreign_key => "author_id" - validates_presence_of :filename + validates_presence_of :container, :filename def file=(incomming_file) unless incomming_file.nil? @@ -35,6 +35,10 @@ class Attachment < ActiveRecord::Base end end + def file + nil + end + # Copy temp file to its final location def before_save if @temp_file && (@temp_file.size > 0) diff --git a/app/views/projects/add_file.rhtml b/app/views/projects/add_file.rhtml index fee67c53f..cb478cb16 100644 --- a/app/views/projects/add_file.rhtml +++ b/app/views/projects/add_file.rhtml @@ -1,14 +1,14 @@

<%=l(:label_attachment_new)%>

<%= error_messages_for 'attachment' %> -<%= start_form_tag ({ :action => 'add_file', :project => @project }, :multipart => true) %> +
+<%= start_form_tag ({ :action => 'add_file', :id => @project }, :multipart => true, :class => "tabular") %> -


-

+

+<%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %>

-

<%=l(:label_attachment)%>
<%= file_field 'attachment', 'file' %>

-
+

+<%= file_field 'attachment', 'file' %>

+
<%= submit_tag l(:button_add) %> <%= end_form_tag %> \ No newline at end of file