How to distinguish the which callback run rails -


i using same method in 2 callbacks before_destroy , before_update. inside method how can check callback called method?

my callbacks:

before_destroy :set_manager_to_true_of_any_trainee before_update :set_manager_to_true_of_any_trainee 

this callback method:

def set_manager_to_true_of_any_trainee   if destroy_callback      # code here   else      # code here   end end 

i doing because 90% code same both callback before_destroy need skip 1 condition.

thanks in advanced.

we can find action transaction belongs to

see method transaction_include_action?

however can't find callback i.e after_create or before_create makes sure transaction belongs create action.

in case can used follows,

if transaction_include_action?(:update) ... else transaction_include_action?(:destroy) ... end 

note:- method deprecated in rails4. , new method introduced transaction_include_any_action?(actions) accepts array of actions. see here

all best!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -