In my paintings controller, show action. I've got a comment form. How
should I pass the painting_id and user_id to the form?
Currently, my paintings controller looks like:
def show
@painting = Painting.find(params[:id])
@comment = Comment.new
....
end
11155
(-- --)
October 14, 2010, 8:46am
2
Hi,
If you have fields like painting_id and user_id in your Comment table
than you can do as follow.
def show
@painting = Painting.find(params[:id])
@comment = Comment.new
@comment.user_id = @painting.user_id # Or your desire value...
@comment.painting_id = @painting.id
end
Thanks
That doesnt work.... the form is submitted but the values user_id and
painting_id are not set in the db. Only the comment is saved
I think you mean:
@comment = Comment.new
@comment.user_id = @painting.user_id # Or your desire value...
@comment.painting_id = @painting.id
MUST be in the comment controller, create action. Not new or show
action....
yes it has to be in the create action of the comment controller and also you have to fetch the painting data so pass it in a hidden field on the form.
@comment = Comment.new
@comment.user_id = @painting.user_id # Or your desire value...
@comment.painting_id = @[painting.id](http://painting.id/)
Yeap, got it. Thanks for clearing that up Radhames