I'm such a dork.  I completely misread the documentation.
"before_validation_on_create" is exactly what I need.  Jeez.
I claim it's been a long week. :-)

Sure glad I could reply to this myself before anyone else had
a chance to, and save a shred of my dignity...

        -glenn

Glenn Little wrote:
> I have an issue where I'm trying to do some validation, but part of
> the validation calculation is based on a value that I want to set
> in a before_create filter.  Unfortunately, before_create is called
> *after* the validation callbacks, so my value isn't available at
> validation time.
> 
> Specifically:
> 
> #-------------------------------------------------
>  validates_uniqueness_of  :account_name,
>                           :scope => :year
> 
>  before_create           :set_year
> 
> (etc etc etc...)
> 
> protected
>  def set_year
>    self.year = <whatever is appropriate>
>  end
> #-------------------------------------------------
> 
> I want to allow account names to repeat, but not within years.
> 
> Is there a clean way to get this behavior without having to mess
> with the constructor?  Messing with the constructor just for this
> when it's called so often in other situations seems ham-fisted.
> 
> Thanks much!
> 
>     -glenn

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to