Skip to content

Instantly share code, notes, and snippets.

@CodeOfficer
Created December 13, 2008 18:15
Show Gist options
  • Save CodeOfficer/35519 to your computer and use it in GitHub Desktop.
Save CodeOfficer/35519 to your computer and use it in GitHub Desktop.
class CreateTextContainers < ActiveRecord::Migration
def self.up
create_table :text_containers do |t|
t.string :formatting
t.text :body
t.boolean :is_published
t.boolean :is_initial_record, :default => true
# ... and all the other revisable fields
t.timestamps
end
end
def self.down
drop_table :text_containers
end
end
My use case requires that a TextContainer be created/saved in an invalid state,
with default values for its fields. On its 'first' update/save I want to
'overwrite' the original ... then every update thereafter I want it revise
as normal.
ie. I'm trying to avoid having that initial invalid record in my
revision history.
class TextContainer < ActiveRecord::Base
acts_as_revisable do
revision_class_name "TextContainerVersion"
end
before_revise :dont_revise_if_initial_record!
def dont_revise_if_initial_record!
if is_initial_record.eql?(true)
self.is_initial_record = false
self.no_revision!
end
end
end
class TextContainerVersion < ActiveRecord::Base
acts_as_revision :revisable_class_name => "TextContainer"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment