after-create

Friendly_id using value from belongs_to association

走远了吗. 提交于 2019-12-23 09:49:07
问题 I have the following models: class User < ActiveRecord::Base extend FriendlyId friendly_id :first_name, :use => :slugged has_one :professor after_create :create_professor def create_professor self.professor = Professor.create end end class Professor < ActiveRecord::Base extend FriendlyId friendly_id :first_name, :use => :slugged belongs_to :user def first_name user.first_name end end At the time that create_professor is called and therefore the execution passes to the Professor model ( self

Rails: Exception in after_create stopping save

倖福魔咒の 提交于 2019-12-18 02:01:29
问题 Simple question. I have a ActiveRecord model that I want to perform post processing on AFTER the record is saved. So in the model I have a queue_for_processing method that sticks a job onto my Resque queue. To make this execute after my record is successfully persisted I have written the following in my model: after_create :queue_for_processing Pretty simple. I had thought that everything was working as expected EXCEPT that last night my redis server went down and things went awry. My

Rails: Exception in after_create stopping save

旧巷老猫 提交于 2019-12-18 02:01:07
问题 Simple question. I have a ActiveRecord model that I want to perform post processing on AFTER the record is saved. So in the model I have a queue_for_processing method that sticks a job onto my Resque queue. To make this execute after my record is successfully persisted I have written the following in my model: after_create :queue_for_processing Pretty simple. I had thought that everything was working as expected EXCEPT that last night my redis server went down and things went awry. My

How should I use after_create with a condition in the model

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 15:44:40
问题 I have a method that is called after the creation of an object after_create :send_welcome_email Is there a way to limit this to a condition, such as the value of an attribute of an object after_create :send_welcome_email unless self.role == "Celebrant" for example? 回答1: There are three ways to do this: Symbol, String, or Proc. class User < ActiveRecord::Base after_create :send_welcome_email, unless: :is_celebrant? after_create :send_welcome_email, unless: "is_celebrant?" after_create :send

Rails: Exception in after_create stopping save

假如想象 提交于 2019-11-28 23:10:27
Simple question. I have a ActiveRecord model that I want to perform post processing on AFTER the record is saved. So in the model I have a queue_for_processing method that sticks a job onto my Resque queue. To make this execute after my record is successfully persisted I have written the following in my model: after_create :queue_for_processing Pretty simple. I had thought that everything was working as expected EXCEPT that last night my redis server went down and things went awry. My expectations were that the record would still be saved and I could process the job later manually. But the