开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜