I want to check the uniqueness of two files, but if the second one is submitted, then nil just ignores the verification of my two models “Assets” and “Company”. Asset has a unique identifier code that I want to do is check the uniqueness of the asset identifier code with the company. we can check it on
class Asset < ActiveRecord::Base validates :identifier, :uniqueness => {:scope => :company_id} end
but it also prevented the use of nil for two assets
how can I ignore checking the uniqueness of the identifier code if its nil
we can pass a block or add except or something similar that we can do with filters in the controller. I am looking for some kind of solution, for example
validates: identifier ,: uniqueness => {: scope =>: company_id} if {: identifier.is_nil? }
can i skip checking with some callback before checking ??
Naveed
source share