Commit bee3f353 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

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
parent 005f4baa
......@@ -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
......
......@@ -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)
......
<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 %>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment