# Another Meta-Programming question (about acts\_as\_versioned)

**URL:** <https://www.ruby-forum.com/t/another-meta-programming-question-about-acts-as-versioned/113243>\
**Category:** Rails\
**Created:** [August 29, 2007, 6:38am UTC](https://www.ruby-forum.com/t/another-meta-programming-question-about-acts-as-versioned/113243 "2007-08-29T06:38:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![supagroova](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e95f7d/32.png) [@supagroova](https://www.ruby-forum.com/u/supagroova)\
**Post date:** [August 29, 2007, 6:38am UTC](https://www.ruby-forum.com/t/another-meta-programming-question-about-acts-as-versioned/113243/1 "2007-08-29T06:38:36Z")

</div>

I’m trying to wrap my head around this meta-programming deal and figured  
I might be able to get some help from the community…

So I am using acts\_as\_versioned for an ActiveRecord model (Page) and I  
want to be able treat the versioned Page (Page::Version) objects as I do  
normal Page objects. To do this there are all the associated methods  
(has\_many, belongs\_to etc) of the Page that need to be added to  
Page::Version.

Below is an abbreviated code snippet:

```auto
class Page < ActiveRecord::Base

  acts_as_versioned :if_changed => [:name, :description, :body,
:address]

  belongs_to :author, :class_name => "User", :foreign_key => "author_id"
  belongs_to :category
  has_many :images, :order => "display_order"
  has_many :attachments, :order => "display_order"
  has_many :comments, :order => "created_at"
  has_many :links, :order => "display_order"
  has_many :references, :order => "display_order"

  def to_param
    address.blank? ? "#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}".downcase :
address.downcase
  rescue
    id.to_s
  end

end
```

And the Page::Version class

```auto
class Page::Version

  def current_page
    self.page
  end

  def to_param
    current_page.to_param
  end

  def author
    current_page.author
  end

  def category
    current_page.category
  end

  def comments
    current_page.comments
  end

  def comments_count
    current_page.comments_count
  end

  def links
    current_page.links
  end

  def references
    current_page.references
  end

  def versions
    current_page.versions
  end

  def images
    current_page.images
  end

  def attachments
    current_page.attachments
  end

end
```

Which is really nasty!!

Any ideas on how I can DRY up the Page::Version class?

Many thanks!
