Thanks for your response.  That fulfilled my implementation goal
perfectly.

Best wishes,
Richard

On Aug 8, 11:41 pm, Ar Chron <[email protected]> wrote:
> RichardOnRails wrote:
> > Hi All,
>
> > 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
> >       errors.add("A vendor must be selected before creating the
> > expense record")
> >     end
> >   end
> > end
>
> > that crashes with:
>
> > undefined local variable or method `params' for #<Expense:0x4716c00>
> > [snip]
>
> Your model by itself knows nothing about params received in the
> controller. And by the time you're looking at validate_on_create, the
> attributes from params have been assigned to the model, IIRC.
>
> What about simply
>
> def validate_on_create
>   unless vendor_id != 0
>     errors.add(blah blah blah)
>   end
> end
> --
> Posted viahttp://www.ruby-forum.com/.

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