OSDN Git Service

fixed bug when no version is selected in projects/add_file
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Dec 2006 16:31:11 +0000 (16:31 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Dec 2006 16:31:11 +0000 (16:31 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@97 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/models/attachment.rb
app/views/projects/add_file.rhtml

index 08b5e0b..a31b7ec 100644 (file)
@@ -340,16 +340,14 @@ class ProjectsController < ApplicationController
     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
index 2e1e9b1..aca86ce 100644 (file)
@@ -21,7 +21,7 @@ class Attachment < ActiveRecord::Base
   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
@@ -35,6 +35,10 @@ class Attachment < ActiveRecord::Base
                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
index fee67c5..cb478cb 100644 (file)
@@ -1,14 +1,14 @@
 <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