开发者

How to update the following lines of rails 3 to include the current_user.user_id

开发者 https://www.devze.com 2023-01-17 06:16 出处:网络
I have a comments table which includes a column for user_id I have the开发者_如何转开发 follow in my comments controller

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
0

精彩评论

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

关注公众号