How should approach allowing users to create notes with revisions?
- by Magicked
I'm working on a Rails project where I want to allow users to create individual notes, which are really just text fields at this time. With each note, the user can edit what they have previously written, but the old version is kept in a revision table. I'm trying to figure out the best way to approach this.
My initial thoughts are to have the following relationships:
class User < ActiveRecord::Base
has_many :notes
end
class Note < ActiveRecord::Base
has_many :note_revisions
belongs_to :user
end
class NoteRevision < ActiveRecord::Base
belongs_to :note_revision
end
The Note model will only contain a timestamp of when the note was first created. The NoteRevision model will contain the text, as well as a timestamp for each revision. This way, every time a new revision is made, a new entry is created into the NoteRevision table which is tracked through the Note table. Hopefully this makes sense!
First, does this look like a good way to do this? If so, I'm having trouble figuring out how the controller and view will present this information in one form. Are there any good tutorials or has someone seen anything similar that can point me in the right direction?
Thanks in advance!