i am trying to develop a wiki with version history.
my plan is: each time i edit a wiki content, it should get saved as a new one.
for now, i have two models, Wiki, and WikiContent, and following code inside them:
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 model has a field current_id, to know which content is the current one.
in Wiki controller i run
def new
@wiki.build_current_wiki
end
def create
@wiki=Wiki.new(params[:wiki])
@wiki.save
@[email protected]_wiki.id
end
But whenever i try to run:
def edit
@wiki.build_new_content
end
it assigns NULL to current_wiki.wiki_id.
how can i fix that? or is there another way to get this to work?