Newbie q about saving data to mysql

I have a two tables in my DB: users and products and I tried to set up a
foreign key relationship between the id field in user and a user_id
field in product.

Despite redoing my scaffold the user_id does not show up when I go to
create a new user. Is that normal?

More importantly, how can I save the user id of the logged in user to
the user_id field in my product table? Currently my create code looks
like this:

def create
@product =[:product]) =
flash[:notice] = ‘Product was successfully created.’
redirect_to :action => ‘list’
render :action => ‘new’

PS: is shows the correct ID of the logged in user so at least
that works…

Ok, solved it.

Dumb mistake. Needed to add this:

 @product.user_id =

You should also be able to say:

@product.user = @user

Which is more idiomatic rails.

– Tom M.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs