如何给current_user分配注释?



这一行在我的create action

@comment = @video.comments.new(params[:comment])

注释也属于创建它的用户。我怎么能把它分配给current_user?它在代码中的什么位置?

 @video.comments.new(params[:comment].merge({:user_id => current_user.id}))

我使用哈希#合并

您还可以:

@comment = @video.comments.new(params[:comment])
@comment.user = current_user

最新更新