Skip to content

Instantly share code, notes, and snippets.

@kanzie
Created May 24, 2011 11:54
Show Gist options
  • Save kanzie/988582 to your computer and use it in GitHub Desktop.
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
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