バージョン履歴のあるwikiを開発しようとしています。
私の計画は次のとおりです。Wikiコンテンツを編集するたびに、新しいコンテンツとして保存する必要があります。
今のところ、私はWikiとWikiContentの2つのモデルを持っており、それらの中に次のコードがあります。
class Wiki < ActiveRecord::Base
has_many :wiki_contents
has_one :current_wiki, :class_name => "WikiContent"
accepts_nested_attributes_for :current_wiki
has_one :new_content, :class_name => "WikiContent"
accepts_nested_attributes_for :new_content
end
class WikiContent < ActiveRecord::Base
belongs_to :wiki
end
Wikiモデルには、現在のコンテンツがどれであるかを知るためのフィールドcurrent_idがあります。
Wikiコントローラーで実行します
def new
@wiki.build_current_wiki
end
def create
@wiki=Wiki.new(params[:wiki])
@wiki.save
@wiki.current_id=@wiki.current_wiki.id
end
しかし、私が実行しようとするときはいつでも:
def edit
@wiki.build_new_content
end
current_wiki.wiki_idにNULLを割り当てます。
どうすれば修正できますか?または、これを機能させる別の方法はありますか?