association loading in documents/show

git-svn-id: http://redmine.rubyforge.org/svn/trunk@24 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2006-10-08 10:42:50 +00:00
parent 5f185b6c05
commit dc26a9cd39
2 changed files with 14 additions and 14 deletions

View File

@ -16,10 +16,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class DocumentsController < ApplicationController class DocumentsController < ApplicationController
layout 'base' layout 'base'
before_filter :find_project, :authorize before_filter :find_project, :authorize
def show def show
@attachments = @document.attachments.find(:all, :order => "created_on DESC")
end end
def edit def edit
@ -48,18 +49,17 @@ class DocumentsController < ApplicationController
@attachment.author_id = self.logged_in_user.id if self.logged_in_user @attachment.author_id = self.logged_in_user.id if self.logged_in_user
@attachment.save @attachment.save
end end
render :action => 'show' redirect_to :action => 'show', :id => @document
end end
def destroy_attachment def destroy_attachment
@document.attachments.find(params[:attachment_id]).destroy @document.attachments.find(params[:attachment_id]).destroy
render :action => 'show' redirect_to :action => 'show', :id => @document
end end
private private
def find_project def find_project
@document = Document.find(params[:id]) @document = Document.find(params[:id])
@project = @document.project @project = @document.project
end end
end end

View File

@ -18,11 +18,11 @@
<br /><br /> <br /><br />
<table border="0" cellspacing="1" cellpadding="2" width="100%"> <table class="listTableContent">
<% for attachment in @document.attachments %> <% for attachment in @attachments %>
<tr style="background-color:#CEE1ED"> <tr class="<%= cycle("odd", "even") %>">
<td><%= format_date(attachment.created_on) %></td>
<td><%= link_to attachment.filename, :action => 'download', :id => @document, :attachment_id => attachment %></td> <td><%= link_to attachment.filename, :action => 'download', :id => @document, :attachment_id => attachment %></td>
<td align="center"><%= format_date(attachment.created_on) %></td>
<td align="center"><%= attachment.author.display_name %></td> <td align="center"><%= attachment.author.display_name %></td>
<td><%= human_size(attachment.filesize) %><br /><%= lwr(:label_download, attachment.downloads) %></td> <td><%= human_size(attachment.filesize) %><br /><%= lwr(:label_download, attachment.downloads) %></td>