To clarify further,

validates :user_id, :presence => true

needs to instead be:

validates :user, :presence => true

Since the user is set usually but the actual id isn't yet. The id is
added to the record
when it's saved to the db / persisted.

Along the same lines, you need to ensure you use something like
@user.socks.build(...) or manually set the user (If you need to let it
be set in the form from a choice
of multiple users, also possibly user_id as mentioned by Jeff).

On Nov 30, 7:00 pm, Darcy Laycock <[email protected]> wrote:
> Try validating presence of user instead of user_id and it shouldn't be an 
> issue.
>
> On 30/11/2010, at 6:56 PM, Rimian Perkins <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi All,
>
> > I've created two models, user and socks where a user has many socks. Then, 
> > I created the migration but when I create a new user and save a new sock, 
> > the user_id is nil and the validation fails.
>
> > I'm really at a loss on how to debug this as it all seems like magic to me. 
> > I'm using devise for user authentication stuff, I don't know if that 
> > matters or not.
>
> > This might help:http://pastebin.com/HSYzPTGU
>
> > Can anyone point me in the right direction? I'm just staring at my code 
> > wondering what to do. I think I might be missing something.
>
> > Cheers,
> > @Rimian
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Ruby or Rails Oceania" 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 
> > athttp://groups.google.com/group/rails-oceania?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" 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/rails-oceania?hl=en.

Reply via email to