Created
November 19, 2010 18:31
-
-
Save airblade/706916 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
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 |
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
<% variables.each do |variable| %> | |
<%= variable.name %><br> | |
<% 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
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