##// END OF EJS Templates
fixed bug when no version is selected in projects/add_file...
Jean-Philippe Lang -
r94:bee3f353fca4
parent child
Show More
@@ -340,16 +340,14 class ProjectsController < ApplicationController
340 render :action => "list_news", :layout => false if request.xhr?
340 render :action => "list_news", :layout => false if request.xhr?
341 end
341 end
342
342
343 def add_file
343 def add_file
344 if request.post?
344 @attachment = Attachment.new(params[:attachment])
345 # Save the attachment
345 if request.post? and params[:attachment][:file].size > 0
346 if params[:attachment][:file].size > 0
346 @attachment.container = @project.versions.find_by_id(params[:version_id])
347 @attachment = @project.versions.find(params[:version_id]).attachments.build(params[:attachment])
347 @attachment.author = logged_in_user
348 @attachment.author_id = self.logged_in_user.id if self.logged_in_user
348 if @attachment.save
349 if @attachment.save
349 flash[:notice] = l(:notice_successful_create)
350 flash[:notice] = l(:notice_successful_create)
350 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
351 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
352 end
353 end
351 end
354 end
352 end
355 @versions = @project.versions
353 @versions = @project.versions
@@ -21,7 +21,7 class Attachment < ActiveRecord::Base
21 belongs_to :container, :polymorphic => true
21 belongs_to :container, :polymorphic => true
22 belongs_to :author, :class_name => "User", :foreign_key => "author_id"
22 belongs_to :author, :class_name => "User", :foreign_key => "author_id"
23
23
24 validates_presence_of :filename
24 validates_presence_of :container, :filename
25
25
26 def file=(incomming_file)
26 def file=(incomming_file)
27 unless incomming_file.nil?
27 unless incomming_file.nil?
@@ -35,6 +35,10 class Attachment < ActiveRecord::Base
35 end
35 end
36 end
36 end
37
37
38 def file
39 nil
40 end
41
38 # Copy temp file to its final location
42 # Copy temp file to its final location
39 def before_save
43 def before_save
40 if @temp_file && (@temp_file.size > 0)
44 if @temp_file && (@temp_file.size > 0)
@@ -1,14 +1,14
1 <h2><%=l(:label_attachment_new)%></h2>
1 <h2><%=l(:label_attachment_new)%></h2>
2
2
3 <%= error_messages_for 'attachment' %>
3 <%= error_messages_for 'attachment' %>
4 <%= start_form_tag ({ :action => 'add_file', :project => @project }, :multipart => true) %>
4 <div class="box">
5 <%= start_form_tag ({ :action => 'add_file', :id => @project }, :multipart => true, :class => "tabular") %>
5
6
6 <p><label for="version_id"><%=l(:field_version)%></label><br />
7 <p><label for="version_id"><%=l(:field_version)%> <span class="required">*</span></label>
7 <select name="version_id">
8 <%= select_tag "version_id", options_from_collection_for_select(@versions, "id", "name") %></p>
8 <%= options_from_collection_for_select @versions, "id", "name" %>
9 </select></p>
10
9
11 <p><b><%=l(:label_attachment)%><b><br /><%= file_field 'attachment', 'file' %></p>
10 <p><label for="attachment_file"><%=l(:label_attachment)%> <span class="required">*</span></label>
12 <br/>
11 <%= file_field 'attachment', 'file' %></p>
12 </div>
13 <%= submit_tag l(:button_add) %>
13 <%= submit_tag l(:button_add) %>
14 <%= end_form_tag %> No newline at end of file
14 <%= end_form_tag %>
General Comments 0
You need to be logged in to leave comments. Login now