Created
December 13, 2008 18:15
-
-
Save CodeOfficer/35519 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 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 |
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
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. | |
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 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 |
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 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