Skip to content

Instantly share code, notes, and snippets.

@airblade
Created November 22, 2010 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airblade/709748 to your computer and use it in GitHub Desktop.
Save airblade/709748 to your computer and use it in GitHub Desktop.
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
<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