# Acts\_as\_commentable, the user\_id of comments always == 0

**URL:** <https://www.ruby-forum.com/t/acts-as-commentable-the-user-id-of-comments-always-0/123330>\
**Category:** Rails\
**Created:** [December 16, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/acts-as-commentable-the-user-id-of-comments-always-0/123330 "2007-12-16T17:33:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![infinit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/76d3ee/32.png) [@infinit](https://www.ruby-forum.com/u/infinit)\
**Post date:** [December 16, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/acts-as-commentable-the-user-id-of-comments-always-0/123330/1 "2007-12-16T17:33:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![infinit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/76d3ee/32.png) [@infinit](https://www.ruby-forum.com/u/infinit)\
**Post date:** [December 16, 2007, 7:17pm UTC](https://www.ruby-forum.com/t/acts-as-commentable-the-user-id-of-comments-always-0/123330/2 "2007-12-16T19:17:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![infinit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/76d3ee/32.png) [@infinit](https://www.ruby-forum.com/u/infinit)\
**Post date:** [December 16, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/acts-as-commentable-the-user-id-of-comments-always-0/123330/3 "2007-12-16T23:51:36Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!
