How to avoid infinite looping when using a callback with rails admin?

115 views
Skip to first unread message

colme...@bol.com.br

unread,
Oct 27, 2020, 3:56:34 PM10/27/20
to rails_admin
Hi all!

I created a method to rate an ingredient according to its caracteristics. But using callbacks at the model after_save, after_commit, after_create etc it is giving me an infinite looping. I can't call the method in the controller because everything is done by the rails_admin. 

Does anybody have any ideia of how get this rate?

def toxicityingredient_classifier
      rated = 0
        rated += 10 if risk_to_health == "red"
        rated += 8 if risk_to_health == "orange"
        rated += 5 if risk_to_health == "yellow"
        rated += 10 if risk_to_enviroment == "red"
        rated += 8 if risk_to_enviroment == "orange"
        rated += 5 if risk_to_enviroment == "yellow"
        rated += 2 if allergenic == "sim"
      self.save(toxicity_ingredient: rated)
  end

Best regards, Amanda 

Philippe Nenert

unread,
Oct 28, 2020, 1:11:20 AM10/28/20
to rails...@googlegroups.com
Hello,
If you are in after_save callback, dont use save method !
Infinite looping !

Use 
  • update_column
  • update_columns

Havé à Nice day 
Philippe 

Le 27 oct. 2020 à 20:56, colme...@bol.com.br <colme...@bol.com.br> a écrit :

Hi all!
--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rails_admin/c8d42213-bba0-4d23-bac4-48994c97a889n%40googlegroups.com.

colme...@bol.com.br

unread,
Oct 28, 2020, 11:32:59 AM10/28/20
to rails...@googlegroups.com
Perfect! Thank you so much!!!

 

 
To view this discussion on the web visit https://groups.google.com/d/msgid/rails_admin/BCD75747-A67A-4F12-8B47-00854ED8A84F%40gmail.com.
Reply all
Reply to author
Forward
0 new messages