How do I assign a comment to current_user?
I have this line in my create
action
@comment = @video.comments.new(params[:comment])
A comment also belongs to the user who creates it. How can I assign it to the current_user? Where does it fit into this code开发者_开发技巧?
@video.comments.new(params[:comment].merge({:user_id => current_user.id}))
I'm using Hash#merge
You can also do:
@comment = @video.comments.new(params[:comment])
@comment.user = current_user
精彩评论