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:
parent
005f4baaa4
commit
bee3f353fc
|
@ -340,16 +340,14 @@ class ProjectsController < ApplicationController
|
||||||
render :action => "list_news", :layout => false if request.xhr?
|
render :action => "list_news", :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_file
|
def add_file
|
||||||
if request.post?
|
@attachment = Attachment.new(params[:attachment])
|
||||||
# Save the attachment
|
if request.post? and params[:attachment][:file].size > 0
|
||||||
if params[:attachment][:file].size > 0
|
@attachment.container = @project.versions.find_by_id(params[:version_id])
|
||||||
@attachment = @project.versions.find(params[:version_id]).attachments.build(params[:attachment])
|
@attachment.author = logged_in_user
|
||||||
@attachment.author_id = self.logged_in_user.id if self.logged_in_user
|
if @attachment.save
|
||||||
if @attachment.save
|
flash[:notice] = l(:notice_successful_create)
|
||||||
flash[:notice] = l(:notice_successful_create)
|
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
||||||
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@versions = @project.versions
|
@versions = @project.versions
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Attachment < ActiveRecord::Base
|
||||||
belongs_to :container, :polymorphic => true
|
belongs_to :container, :polymorphic => true
|
||||||
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
||||||
|
|
||||||
validates_presence_of :filename
|
validates_presence_of :container, :filename
|
||||||
|
|
||||||
def file=(incomming_file)
|
def file=(incomming_file)
|
||||||
unless incomming_file.nil?
|
unless incomming_file.nil?
|
||||||
|
@ -35,6 +35,10 @@ class Attachment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
# Copy temp file to its final location
|
# Copy temp file to its final location
|
||||||
def before_save
|
def before_save
|
||||||
if @temp_file && (@temp_file.size > 0)
|
if @temp_file && (@temp_file.size > 0)
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<h2><%=l(:label_attachment_new)%></h2>
|
<h2><%=l(:label_attachment_new)%></h2>
|
||||||
|
|
||||||
<%= error_messages_for 'attachment' %>
|
<%= 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 />
|
<p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
|
||||||
<select name="version_id">
|
<%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>
|
||||||
<%= options_from_collection_for_select @versions, "id", "name" %>
|
|
||||||
</select></p>
|
|
||||||
|
|
||||||
<p><b><%=l(:label_attachment)%><b><br /><%= file_field 'attachment', 'file' %></p>
|
<p><label for="attachment_file"><%=l(:label_attachment)%> <span class="required">*</span></label>
|
||||||
<br/>
|
<%= file_field 'attachment', 'file' %></p>
|
||||||
|
</div>
|
||||||
<%= submit_tag l(:button_add) %>
|
<%= submit_tag l(:button_add) %>
|
||||||
<%= end_form_tag %>
|
<%= end_form_tag %>
|
Loading…
Reference in New Issue