Hey Rails riders, I have a question regarding a membership application I''m creating. In the application customers can sign up and then administrators from the actual organization process their application by simply pulling it up in the rails system and assigning them a membership card number from a stack followed by mailing them the physical card. The problem is I have a model with the members information along with a field for the card id. I want to validate that this field is unique but it also needs to be blank until a staff member actually assigns them a card ID. What is the best way to do this? - Jim
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
2005-Sep-06 03:14 UTC
Re: Validating Uniqueness of a non-required field.
Hello Jim, Jim Jeffers said the following on 2005-09-05 17:46:> The problem is I have a model with the members information along with a > field for the card id. I want to validate that this field is unique > but it also needs to be blank until a staff member actually assigns > them a card ID. What is the best way to do this?Simply allow nil, as in: validates_uniquess_of :card_id, :if => Proc.new {|rec| no rec.card_id.blank? } That should do the trick nicely. As an aside, I think this method should also support :allow_nil. Any takers ? Bye ! François