Make acts_as_versioned know target model belongs_to association
acts_as_versioned is a great plug-in for Rails. It can keep track of all modifications to your target model with only a little setup. But it seems not support has_*/belongs_to association by default. So let’s see how to enable this.
Assume that you are going to keep track of the ‘Post’ model. and this is probably your model looks like:
class Post < ActiveRecord::Base
acts_as_versioned
belongs_to :user
end
But version.user will not work (at least, for this version).
(1) For newer version of acts_as_versioned, try this: class Post < ActiveRecord::Base acts_as_versioned do belongs_to :user end end
(2) And for older version, try this: class Post < ActiveRecord::Base acts_as_versioned belongs_to :user end
Post.versioned_class.class_eval do
belongs_to :user
end
solution 2 works for me! but solution 1 not (ruby 1.8.6, rails 2.3.2, acts_as_versioned 0.3.1)
喜歡這篇文章嗎?你可能也會喜歡我的學習電子報,我會分享經過篩選的優質內容 + 學習心得
📚 訂閱我的學習電子報
📖 涵蓋主題:
✨ 不浪費你的時間,只分享達到我標準的優質內容