How to update the following lines of rails 3 to include the current_user.user_id
I have a comments table which includes a column for user_id
I have the开发者_如何转开发 follow in my comments controller
def create
@commentable= context_object()
@comment = @commentable.comments.build(params[:comment])
.
.
Problem is this doesn't pass the current_user's user_id. How can I update the above to be something like current_user.comments.build....
Thanks
The easiest would be to just do:
@comment.user = current_user
You should be able to do this too:
current_user.comments << @comment
精彩评论