render :action => "list_news", :layout => false if request.xhr?\r
end\r
\r
- def add_file \r
- if request.post?\r
- # Save the attachment\r
- if params[:attachment][:file].size > 0\r
- @attachment = @project.versions.find(params[:version_id]).attachments.build(params[:attachment]) \r
- @attachment.author_id = self.logged_in_user.id if self.logged_in_user\r
- if @attachment.save\r
- flash[:notice] = l(:notice_successful_create)\r
- redirect_to :controller => 'projects', :action => 'list_files', :id => @project\r
- end\r
+ def add_file\r
+ @attachment = Attachment.new(params[:attachment])\r
+ if request.post? and params[:attachment][:file].size > 0 \r
+ @attachment.container = @project.versions.find_by_id(params[:version_id])\r
+ @attachment.author = logged_in_user\r
+ if @attachment.save\r
+ flash[:notice] = l(:notice_successful_create)\r
+ redirect_to :controller => 'projects', :action => 'list_files', :id => @project\r
end\r
end\r
@versions = @project.versions\r
belongs_to :container, :polymorphic => true\r
belongs_to :author, :class_name => "User", :foreign_key => "author_id"\r
\r
- validates_presence_of :filename\r
+ validates_presence_of :container, :filename\r
\r
def file=(incomming_file)\r
unless incomming_file.nil?\r
end\r
end\r
\r
+ def file\r
+ nil\r
+ end\r
+ \r
# Copy temp file to its final location\r
def before_save\r
if @temp_file && (@temp_file.size > 0)\r
<h2><%=l(:label_attachment_new)%></h2>\r
\r
<%= error_messages_for 'attachment' %>\r
-<%= start_form_tag ({ :action => 'add_file', :project => @project }, :multipart => true) %>\r
+<div class="box">\r
+<%= start_form_tag ({ :action => 'add_file', :id => @project }, :multipart => true, :class => "tabular") %>\r
\r
-<p><label for="version_id"><%=l(:field_version)%></label><br />\r
-<select name="version_id">\r
-<%= options_from_collection_for_select @versions, "id", "name" %>
-</select></p>\r
+<p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>\r
+<%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>\r
\r
-<p><b><%=l(:label_attachment)%><b><br /><%= file_field 'attachment', 'file' %></p>\r
-<br/>\r
+<p><label for="attachment_file"><%=l(:label_attachment)%> <span class="required">*</span></label>\r
+<%= file_field 'attachment', 'file' %></p>\r
+</div>\r
<%= submit_tag l(:button_add) %>\r
<%= end_form_tag %>
\ No newline at end of file