ruby on rails - How to scope validation to specific model in polymorphic association.? -
i have 2 model user
, investment
, 1 polymorhic model address
class user < activerecord::base has_one :address, as: :addressable, dependent: :destroy accepts_nested_attributes_for :address end class investment < activerecord::base has_many :addresses, as: :addressable, dependent: :destroy accepts_nested_attributes_for :addresses, reject_if: lambda { |v| v['address'].blank? } && :address_blank, :allow_destroy => true end class address < activerecord::base belongs_to :addressable, polymorphic: true validates :address, presence: true end
now validates :address, presence: true
applicable both investment
user
want applicable investment
not user
. how do that.
thanks.
in class investment add
validates :address_id, presence: true
and remove bellow class address
validates :address, presence: true
Comments
Post a Comment