I created an instance variable (@edit_id) in the user_controller the update action.
def update
......
@edit_id = 1
......
end
and I have an Active Record Callbacks in the user_model
has_many :details
after_update :create_user_details
......
private
def create_user_details
detail = user.details.build
detail.edit_id = @edit_id
#(this @edit_id is the user_controller update action
#created instance variable, but **@edit_id is nil**)
detail.save
end
I how use the instance variable in the callback action
You cannot use instance variables from your controller in your model.
They both are different instances of different objects and therefore don’t share instance variables.
You need to provide your model with this value by setting it in it’s instance like this :
Then, in your controller, you specify the value to the model and save it.