Acts_as_commentable, the user_id of comments always == 0

I used the acts_as_commentable in my app.
But I find that, the user_id in comments table all equal0, I hv
declaraed in the
user model:
has_many :comment,
and I hv tried move the comment.rb in the model directory. but the
user_id stays 0 whenever I add a comment.
So do I need add one line when add a comment : comment.user_id =
current_user.id ? or can we solved in other approach? ( as I think
this user_id should be added automatically and correctly by the
plugin).

Thanks for your help.

infinit

I think that is correct. user_id is the ID of the person making the
comment, which can be zero if you don’t care about keeping track of
who make what comments or allow anonymous comments.

you have to set it manually. the has_many: comments association only
allows you to do this

User.find( 1).comments

It should be has_many :comments

rubynuby already said this but I thought I would make it clearer.

In the controller yes you would have to do something like:

@comment = Comment.create!(params[:comment].merge(:user_id =>
current_user.id))

Rails does not do this automatically for you.
On Dec 17, 2007 4:46 AM, rubynuby [email protected] wrote:


Ryan B.