Ruby on rails 排名系统未更新数据库记录
我正在建立一个简单的排名系统。当一条评论被投票支持时,用户的Ruby on rails 排名系统未更新数据库记录,ruby-on-rails,Ruby On Rails,我正在建立一个简单的排名系统。当一条评论被投票支持时,用户的排名将得到提升。@comment.rating将按其应做的方式更新和保存。但是,@comment.user.rank没有。它不报告任何错误,只是从不尝试更新或保存它 这是“我的评论”控制器中的方法: def increment @comment = Comment.find(params[:id]) @comment.rating += 1 @comment.user.rank += User::RANK_VALUES["c
排名将得到提升。@comment.rating
将按其应做的方式更新和保存。但是,@comment.user.rank
没有。它不报告任何错误,只是从不尝试更新或保存它
这是“我的评论”控制器中的方法:
def increment
@comment = Comment.find(params[:id])
@comment.rating += 1
@comment.user.rank += User::RANK_VALUES["comment_plus"]
if @comment.save
flash[:notice] = "Voted up"
redirect_to(:back)
else
flash[:notice] = "Error"
redirect_to(:back)
end
end
这是通过以下链接调用的
:
<%= link_to "+", :controller => "comments", :action => "increment", :id => comment.id %>
关于@comment.user.rank更新被忽略的原因有什么想法吗?
注意:我传递的散列应该可以;我还尝试输入一个具有相同结果的整数。尝试调用
@comment.user.save代码>也是。您正在保存注释,但没有保存关联的模型。没问题!很高兴我能帮忙!
Started GET "/comments/increment/12" for 127.0.0.1 at Wed Aug 24 22:35:39 -0400 2011
Processing by CommentsController#increment as HTML
Parameters: {"id"=>"12"}
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."id" = 12 LIMIT 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
AREL (0.2ms) UPDATE "comments" SET "rating" = 9, "updated_at" = '2011-08-25 02:35:39.315081' WHERE "comments"."id" = 12
Redirected to http://localhost:3000/photos/6