Created
May 24, 2011 11:54
-
-
Save kanzie/988582 to your computer and use it in GitHub Desktop.
Cant get the association to work so I can count number of revisions per document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Model pdm_documents: | |
class PdmDocument < ActiveRecord::Base | |
has_many :revisions | |
End | |
Model pdm_revisions: | |
class PdmRevision < ActiveRecord::Base | |
belongs_to :document | |
end | |
Controller pdm_documents_controller | |
class PdmDocumentsController < ApplicationController | |
def index | |
@project = Project.find(params[:project_id]) | |
@documents = PdmDocument.find(:all) | |
end | |
View index: | |
<% if not @documents.nil? %> | |
<% @documents.each do |document| %> | |
<tr <%= cycle("odd", "even") %>"> | |
<td><%= link_to(image_tag('document.png'), {:action => 'download', :id => document}) %></td> | |
<td><%= document.time_stamp %></td> | |
<td><%= link_to document.name, { :controller => "pdm_revisions", :action => "index" , :id => document, :project_id => @project }%></td> | |
<td><%= document.last_revision_by %></td> | |
<td><%= document.revisions.count %></td> | |
</tr> | |
<% end %> | |
<% end %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment