public
Description: A workaround to ensure multiparameter assignment still works when you delegate date/time Active Record attributes
Homepage:
Clone URL: git://github.com/jonleighton/delegate_temporal.git
name age message
file MIT-LICENSE Wed Sep 10 02:53:09 -0700 2008 Initial import [jonleighton]
file README.textile Wed Sep 10 02:53:09 -0700 2008 Initial import [jonleighton]
file Rakefile Wed Sep 10 02:53:09 -0700 2008 Initial import [jonleighton]
file init.rb Loading commit data...
file install.rb Wed Sep 10 02:53:09 -0700 2008 Initial import [jonleighton]
directory lib/ Thu Sep 11 04:33:56 -0700 2008 Don't assign an empty hash to the attributes of... [jonleighton]
directory spec/
directory tasks/ Wed Sep 10 02:53:09 -0700 2008 Initial import [jonleighton]
file uninstall.rb Wed Sep 10 02:53:09 -0700 2008 Initial import [jonleighton]

Delegate Temporal

This Rails plugin allows you to continue to use multiparameter attributes when the actual attribute is delegated to another object.

The problem

class Foo < ActiveRecord::Base
  ...
  delegate :start_time, :start_time=, :to => :appointment
end

@foo.attributes = { "start_time(1i)" => "2008", "start_time(2i)" => "9", ... }
# => Error!

The error occurs because Rails tries to look up the “start_time” column in the database (in order to find out information about its type), but because we are delegating it doesn’t exist.

The solution

Install this plugin, and then:

class Foo < ActiveRecord::Base
  ...
  delegate_temporal :start_time, :to => :appointment
end

@foo.attributes = { "start_time(1i)" => "2008", "start_time(2i)" => "9", ... }
# => Yay, it works!