Rails how to update a column after saving?

前端 未结 5 2091
栀梦
栀梦 2020-12-15 08:09

I want to create an after_save method for my rate action. It would divide rating_score/ratings and update the column rating.

class KonkurrancersController &         


        
5条回答
  •  轮回少年
    2020-12-15 08:43

    Not sure why people are upvoting the wrong answer and downvoting the correct answer.

    Zakelfassi is right and Christian Fazzini is wrong for Rails 3 and above. If you do #update_attributes in a save callback you go into an endless recursion. You want to do #update_column as per his example.

    Try it for yourself and you'll see.

提交回复
热议问题