diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2011-05-17 20:37:11 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2011-05-17 20:43:30 +0100 |
commit | 42f1ad68655be08a0ff7e5a261d1ad21d3fc90a5 (patch) | |
tree | b38279cb013fdce55ff81329a44aa55b29460a7c /activerecord/test/models | |
parent | b81f77e2e23d3792cd95f7b86158875a3a6a0dc2 (diff) | |
download | rails-42f1ad68655be08a0ff7e5a261d1ad21d3fc90a5.tar.gz rails-42f1ad68655be08a0ff7e5a261d1ad21d3fc90a5.tar.bz2 rails-42f1ad68655be08a0ff7e5a261d1ad21d3fc90a5.zip |
Pass the attribute and option hashes to build_association
The build_association method was added as an API for plugins
to hook into in 1398db0. This commit restores this API and the
ability to override class.new to return a subclass based on
a virtual attribute in the attributes hash.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/bulb.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index 7d90963720..0dcc8d5970 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -15,4 +15,17 @@ class Bulb < ActiveRecord::Base self[:color] = color.upcase + "!" end + def self.new(attributes = {}, options = {}, &block) + bulb_type = (attributes || {}).delete(:bulb_type) + + if options && options[:as] == :admin && bulb_type.present? + bulb_class = "#{bulb_type.to_s.camelize}Bulb".constantize + bulb_class.new(attributes, options, &block) + else + super + end + end end + +class CustomBulb < Bulb +end
\ No newline at end of file |