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