Created
November 25, 2010 19:13
-
-
Save schovi/715801 to your computer and use it in GitHub Desktop.
How to mass assign attribute 'type' for STI with validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ActiveRecord::Base | |
validates_inclusion_of :type, :in => %w{SpecialOrder} | |
def self.new(params = {}) | |
_type = params.delete(:type) | |
_new = super(params) | |
_new.type = _type.to_s.camelize if _type | |
return _new | |
end | |
end | |
class SpecialOrder < Order | |
end | |
order = Order.new :type => "special_order", :other_attribute => .... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment