开发者

How do I assign a comment to current_user?

开发者 https://www.devze.com 2023-02-22 03:16 出处:网络
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 i

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

精彩评论

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