Hi Hassan,

Thanks for your response.

> At that point your instance of Expense should already have its
vendor_id value -- kinda the point -- so unless self.vendor_id != 0 #
or whatever -- what if it's nil? :-)

It can't be nil.  When the form is instantiated,  the Vendor drop-down
is initialized with:
1.  vendor_id == 0
2.  drop-down text = "=== Select a Vendor ==="

If the new expense record is to be created with vendor_id == 0, then
the user failed to associate a Vendor with the subject expense, and
that's invalid for this application.  Therefore, the app needs to:
1. present an error-message at the top of the form
2. re-display all other form elements with their current content

Make sense?

Best wishes,
Richard

On Aug 8, 8:48 pm, Hassan Schroeder <[email protected]>
wrote:
> On Sun, Aug 8, 2010 at 4:18 PM, RichardOnRails
>
> <[email protected]> wrote:
> > I've got an Expense model as follows:
>
> > class Expense < ActiveRecord::Base
> >  belongs_to :vendor
>
> >  def validate_on_create
> >    unless params["expense"]["vendor_id"] != "0"   # <= Line 5
>
> ?? At that point your instance of Expense should already have its
> vendor_id value -- kinda the point -- so
>
>   unless self.vendor_id != 0 # or whatever -- what if it's nil? :-)
>
> HTH,
> --
> Hassan Schroeder ------------------------ [email protected]
> twitter: @hassan

-- 
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