On Oct 11, 9:38 am, Joshua Muheim <[email protected]>
wrote:
> This works great so far. But I remarked that this way the data in any
> Page object will only be valid after the call of valid? or safe (or any
> other such related methods). So before doing this, it's possible that I
> have invalid data in a Page object!
>
> My question: is this OK? Or should I overwrite the body=() method or
> something to make the "magic" happen as soon as the body itself changes?
>
> Or is it agreed that modified AR objects can have temporary invalidities
> as long as they're not safed/validated?
>

While generally I agree with the idea of "don't optimize prematurely",
there's a line between that idea and "don't write clearly slow code".
I think overriding body= here is a good idea, since the
before_validation callback will fire every time the record is saved,
even if body hasn't changed. Normally that's OK, but instantiating a
Nokogiri parser is quite a bit heavier than the typical validation
action...

--Matt

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to