Monday, September 29, 2008

Advanced Rails Recipes - Chapter Two - The missing copy method.

I am reading through the Advanced Rails Recipes book. In chapter two, it refers to an Event.copy method which is not shown in the book. Shown below is the missing method from app/models/event.rb.

class Event < ActiveRecord::Base

  def self.copy(other)
    self.new(other.attributes.merge(:name => "Copy of #{other.name}"))
  end

end