On a past project where we wanted something like an after_filter to
check whether the user input was valid, it just looked at
@whatever.errors.empty? to avoid rerunning the validations. Obviously
that makes assumptions about what the action has done, but I think
they're the same assumptions you'd have to make to use your API.

That seems like a good idea for an application that needs to track
that in a few places, but I'd rather see it stay in a plugin than
become part of core. It seems to crowd the API a bit, and adds
something not many people need.

I could see people getting confused by the following, thinking #saved?
should be the opposite of #new_record?.

  t = Thing.find(:first)
  t.new_record? # => false
  t.saved?      # => nil
  puts "But it's in the database! It is sooo saved!"

If people like this feature, I'd like to see #saved? renamed to reduce
the likelihood of the above. Maybe "instance_saved?" is better, but I
can still imagine people not grokking it until it's bitten them.

On a separate note, I think it's surprising to have a predicate method
return nil.

-hume.
---
http://elhumidor.blogspot.com/


On Mon, Sep 8, 2008 at 5:50 AM, Ian White <[EMAIL PROTECTED]> wrote:
> One way of doing this would be to use #valid?, but this will hit the
> database again in some cases (e.g. if there's a
> validates_uniqueness_of), which I want to avoid.
>
> I'm proposing a very simple API, as described here 
> http://www.pastie.org/268045
> .
> To make this work is also very simple (here's a plugin verision 
> http://pastie.org/268046)
> .
>
> Before I bundle this up into a patch with tests, I'm wondering if
> people think this is a good or bad idea?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" 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-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to