Skip to content

Instantly share code, notes, and snippets.

@airblade
Created November 19, 2010 18:31
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/706916 to your computer and use it in GitHub Desktop.
Save airblade/706916 to your computer and use it in GitHub Desktop.
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
<% variables.each do |variable| %>
<%= variable.name %><br>
<% end %>
class Keyword < ActiveRecord::Base
has_paper_trail :meta => {:publication_id => Proc.new { |keyword| keyword.publication_id }}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment