I set up a field in my products table called user_id where hope to track the user associated with a particular product.
I regenerated my scaffold but that user_id field is not showing up.
That in itself is not the big deal, but I'm tryinto figure out how to save the id of the user to that user_id field.
I can grab the correct id in the @user.id variable but can't figure out how to save it.
The complete section of the code (based on the agiles example) is here:
def create warn @user.id @product = Product.new(params[:product]) #@product.id = @user.id (did not work) if @product.save flash[:notice] = 'Product was successfully created.' redirect_to :action => 'list' else render :action => 'new' end end
If anyone has any suggestions.. I'm a stuck little newbie at the moment..
To get this clear, are you trying to keep track of which administrative user created a new product by grabbing the id of whatever user is logged in? My first guess would be that the problem with your controller code is that you just didn't have the right attribute for the product variable:
@product.user_id = @user.id instead of @product.id = @user_id
Although I'm not exactly sure how you're setting the @user instance variable...wouldn't the proper way be to grab the user id directly from the session? (assuming you've stuck pretty closely to the Agile's Depot application):
@product.user_id = session[:user_id]
I could have sworn I had tried that...
Anyway, that works.. thanks for the help!