Questions tagged [after-create]

37 questions
22
votes
1 answer

Rails: Exception in after_create stopping save

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…
James P McGrath
  • 1,856
  • 1
  • 20
  • 35
17
votes
1 answer

How should I use after_create with a condition in the model

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 ==…
chell
  • 7,646
  • 16
  • 74
  • 140
14
votes
1 answer

Rails - execution sequence of after create callback & nested attributes

I have a simple set up of User and UserProfile model with User has_one :user_profile and UserProfile belongs_to :user. But I am unable to wrap my head around how Rails defines execution order of after_create callback and…
prasvin
  • 3,009
  • 23
  • 28
5
votes
1 answer

Friendly_id using value from belongs_to association

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 …
Nobita
  • 23,519
  • 11
  • 58
  • 87
3
votes
1 answer

How to get session parameters in afterCreate of sails model

I want to get get current logged in user in a models afterCreate callback. In controller, current logged in user is found form the request header-req.user. But in model's life-cycle callback the session header is not passed. Is there any way to find…
hasan3050
  • 195
  • 2
  • 10
3
votes
1 answer

counter_cache is stale in after_create hook

I rely on a counter cache value in an after_create hook of my model. However, my hook is called before the counter cache gets updated, thus breaking a computation. Is there any way to force a counter cache "flush" so that I always see an up-to-date…
mxk
  • 43,056
  • 28
  • 105
  • 132
2
votes
1 answer

Oracle AFTER/BEFORE CREATE ON DATABASE trigger: how to access object sources

I am trying to implement pseudo version control and repository for Oracle. The idea is: when a stored function/procedure is altered or a created global DATABASE trigger is fired, which would grab the current sources of a modified object and store…
Dimus
  • 35
  • 2
  • 5
2
votes
1 answer

Rails 3 how to get the current record ID in after_create

Like the title said, I'm trying to get the ID of the record I just created, I tried to get it in the console but the ID is nil. Here is the print I got of self in the console at the beginning of after_create
Incognito
  • 493
  • 2
  • 8
  • 22
2
votes
2 answers

Can't grab foreign key during after_create callback because it doesn't exist yet!

I have some models all linked together in memory (parent:child:child:child) and saved at the same time by saving the top-most parent. This works fine. I'd like to tap into the after_create callback of one of the children to populate a changelog…
1
vote
0 answers

rails state_machine with after_create callback and validation on_update

I am using the state_machine gem in a model Event. The initial state of an event is pending. When I create an event I would like to run an after_create callback to see if I can make the first transition depending on the attributes of the event.…
jagse
  • 333
  • 4
  • 18
1
vote
2 answers

Rails3 - Adding default values to associated table after_create

I'am looking for a way to add intiatlize an associated DB after the parent is created. I have a simple User model with just the filed username and a related (has_many) child Place model with the field placenames. After the user was created…
1
vote
1 answer

Rails: Skip after_create

I have 2 models: class User < ActiveRecord::Base has_one :client end class Client < ActiveRecord::Base belongs_to :user end and I normally create a user first, and have an after_create filter, to create the client after the user has been…
Jeremy Thomas
  • 6,240
  • 9
  • 47
  • 92
1
vote
1 answer

rails after_create with devise

I have this code in my user model class User < ActiveRecord::Base after_create :set_user_full_name ......... private def set_user_full_name self.name = "Test name" end end But when I create a user the name attribute is nil. I tried…
fardin
  • 1,399
  • 4
  • 16
  • 27
1
vote
1 answer

Fields that are a relationships dont be appeared by callback create in SailsJS

I have the following Media schema module.exports = { attributes: { user: { model: 'user', required: true }, jobs: { collection: 'job', …
1
vote
1 answer

automatically create an associated record after creation of a parent record

I am building a Project app and I need to automatically generate 1 Participant on creation of a Project record. My model class Project < ActiveRecord::Base has_many :participants, dependent: :destroy, inverse_of: :project after_create…
NothingToSeeHere
  • 2,253
  • 5
  • 25
  • 57
1
2 3