Re: Update attributes

Mike Garey
Fri, 16 Feb 2007 22:47:20 -0000

what you''re doing looks fine, and the database query is definitely
strange, but somewhere along the line, rails is executing a find
without an ID.

The application trace doesn''t show what line in your code is causing
the error.

Using validates_presence_of shouldn''t have any side effect, unless
you''re modifying it with an "if" condition and introducing an
error at
that point.

Mike

On 2/16/07, namwob <ebowman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
> Can someone explain why "validates_presence_of" screws up a call
to
> update a model object?
>
> On Feb 16, 2:11 pm, "namwob"
<ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > The issue that I can''t grasp is why this call was made in my
log file
> > for a simple update call
> >
> > SELECT * FROM users WHERE
> > (users.name = ''joseph'' AND users.id <> 11)
> >
> > On Feb 16, 2:06 pm, "Mike Garey"
<random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > > what exact line is causing rails to throw that error?
> >
> > > On 2/16/07, namwob
<ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > > > The id does get passed.  Note from my dev.log file the
parameters
> > > > getting passed:
> >
> > > > Parameters:
{"user"=>{"name"=>"joseph",
> > > >
"hashed_password"=>"3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352",
> > > > "user_type"=>"nelnet",
"user_role"=>"user"}, "commit"=>"
Update User
> > > > ", "action"=>"update_user",
"id"=>"11", "controller"=>"admin"}
> >
> > > > id is listed, so it makes it to the controller.
> >
> > > > On Feb 16, 2:01 pm, "Mike Garey"
<random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > > > > On 2/16/07, namwob
<ebow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > > > > > I am a bit confused as to why I am getting an
error updating an
> > > > > > object.
> >
> > > > > > This is the ERROR:  Couldn''t find User
without an ID
> >
> > > > > before you start getting to the strange SQL call, try
and find out why
> > > > > an ID isn''t being passed.  At what line do you
receive this error? At
> > > > > the User.find(params[:id]) ? If so, find out why
you''re not getting a
> > > > > value for an id here, then try to figure out the next
part.
> >
> > > > > Mike