Created
November 22, 2010 09:39
-
-
Save airblade/709748 to your computer and use it in GitHub Desktop.
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
class PublicationsController < ActionController::Base | |
def show | |
@publication = Publication.find params[:id] | |
# If you need a specific version, get that from the URL. | |
version_id = ... | |
@publication = @publication.versions.find version_id | |
keywords = [] # the keywords belonging to @publication at the time | |
keywords_versions = Version.all :item_type => 'Keyword', :publication_id => @publication.id | |
keywords_versions.group_by(&:item_id).each do |item_id, versions| | |
v = versions.first :conditions => ['created_at > ?', (@publication.created_at - 3.seconds)] | |
keywords << (v ? v.reify : Keyword.find(item_id)) | |
end | |
@variables = keywords.map do |keyword| | |
variable = keyword.variable | |
# Handle situation where variable has since been destroyed | |
unless variable | |
variable = Version.last(:item_type => 'Variable', :item_id => keyword.variable_id).reify | |
end | |
variable | |
end | |
end | |
end |
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
<h1><%= @publication.name %></h1> | |
<h2>Variables</h2> | |
<% variables.each do |variable| %> | |
<%= variable.name %><br> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment