Try the "if" option, mentioned here:
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000816
So you could, for example, add one of
:if => "!canceled"
:if => Proc.new {|invitee| !invitiee.canceled }
:if => not_canceled? # where not_canceled is a method in your Invitee class
On Tuesday 19 December 2006 10:06 am, Craig Jolicoeur
wrote:> I have an Invitee model that has the following fields: id, user_id,
> invitation_id, email, created_at, canceled
>
> In the Invitee model I have the following validation:
>
> validates_uniqueness_of :email,
>
> :scope => ''user_id'',
> :message => ''invitation already sent to
that
>
> address''
>
>
> The model is for an invitation system to invite users to join the
> website. I only want each user to send an invitation to an email
> address one time. Different users can invite the same email address,
> but each individual user can only invite an email address one time. The
> ":scope => ''user_id''" accomplishes this fine
for me.
>
> However, when a user cancels and invite, I set the canceled flag to
"1"
> to signifiy the invitation was canceled. If the invitation is canceled,
> I then want to allow that user to send a new invitation to that same
> email address again if they want to.
>
> Can I do this with model validations? Right now, my
> "validates_uniqueness_of" doesn''t look at the canceled
field, and even
> if the user cancels an invite they still can''t send an invite
again
> because they have already invited that email address. Is there some
> kind of different option or different use of :scope that I can do to
> handle this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---