How should one pass params to the comment form

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

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…

On Oct 14, 5:15pm, Christian F. [email protected]

On Thu, Oct 14, 2010 at 5:43 AM, Christian F. <
[email protected]> wrote:

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

Yeap, got it. Thanks for clearing that up Radhames