use*_*279 2 ruby-on-rails mongodb mongoid ruby-on-rails-4
为什么我会收到此错误?我没有想法.
undefined method `update_attributes' for #
码:
exists = Vote.where(comment_id: @comment.id).exists?
if exists
update_vote = Vote.where(comment_id: @comment.id)
update_vote.update_attributes(value: 5)
redirect_to :back
else
Run Code Online (Sandbox Code Playgroud)
你想要特别获取一条记录,所以告诉它:
update_vote = Vote.where(comment_id: @comment.id).first
Run Code Online (Sandbox Code Playgroud)
但是如果没有匹配的话,这段代码很容易出错,请注意.
| 归档时间: |
|
| 查看次数: |
3267 次 |
| 最近记录: |