fixed bug when no version is selected in projects/add_file

git-svn-id: http://redmine.rubyforge.org/svn/trunk@97 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2006-12-16 16:31:11 +00:00
parent 005f4baaa4
commit bee3f353fc
3 changed files with 20 additions and 18 deletions

View File

@ -341,17 +341,15 @@ class ProjectsController < ApplicationController
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
@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
end
@versions = @project.versions
end

View File

@ -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)

View File

@ -1,14 +1,14 @@
<h2><%=l(:label_attachment_new)%></h2>
<%= error_messages_for 'attachment' %>
<%= start_form_tag ({ :action => 'add_file', :project => @project }, :multipart => true) %>
<div class="box">
<%= start_form_tag ({ :action => 'add_file', :id => @project }, :multipart => true, :class => "tabular") %>
<p><label for="version_id"><%=l(:field_version)%></label><br />
<select name="version_id">
<%= options_from_collection_for_select @versions, "id", "name" %>
</select></p>
<p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
<%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>
<p><b><%=l(:label_attachment)%><b><br /><%= file_field 'attachment', 'file' %></p>
<br/>
<p><label for="attachment_file"><%=l(:label_attachment)%> <span class="required">*</span></label>
<%= file_field 'attachment', 'file' %></p>
</div>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>