开发者

How should approach allowing users to create notes with revisions?

I'm working on a Rails project where I want to allow users to create i开发者_运维技巧ndividual 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!


I'd check out paper trail which will handle all the versioning for you and help you easily return the most current version. Behind the scenes it does something similar to what you're attempting to do but has been thoroughly tested and used by many people. It also benefits from active development.


Another option is the vestal_versions gem. Railscasts.com has an episode on using it: http://railscasts.com/episodes/177-model-versioning

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜