HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/ruby-2.5.9/doc/activemodel-6.1.4.1/ri/ActiveModel/Callbacks/cdesc-Callbacks.ri
U:RDoc::NormalModule[iI"Callbacks:ETI"ActiveModel::Callbacks;T0o:RDoc::Markup::Document:@parts[o;;[ S:RDoc::Markup::Heading:
leveli:	textI"Active \Model \Callbacks;To:RDoc::Markup::BlankLineo:RDoc::Markup::Paragraph;[I"NProvides an interface for any class to have Active Record like callbacks.;T@o;
;[I"NLike the Active Record methods, the callback chain is aborted as soon as ;TI"(one of the methods throws +:abort+.;T@o;
;[I"JFirst, extend ActiveModel::Callbacks from the class you are creating:;T@o:RDoc::Markup::Verbatim;[I"class MyModel
;TI"%  extend ActiveModel::Callbacks
;TI"	end
;T:@format0o;
;[I"GThen define a list of methods that you want callbacks attached to:;T@o;;[I"-define_model_callbacks :create, :update
;T;0o;
;[	I"OThis will provide all three standard callbacks (before, around and after) ;TI"Ofor both the <tt>:create</tt> and <tt>:update</tt> methods. To implement, ;TI"Oyou need to wrap the methods you want callbacks on in a block so that the ;TI"$callbacks get a chance to fire:;T@o;;[
I"def create
;TI"   run_callbacks :create do
;TI"+    # Your create action methods here
;TI"  end
;TI"	end
;T;0o;
;[I"MThen in your class, you can use the +before_create+, +after_create+ and ;TI"J+around_create+ methods, just as you would in an Active Record model.;T@o;;[
I")before_create :action_before_create
;TI"
;TI"def action_before_create
;TI"  # Your code here
;TI"	end
;T;0o;
;[I"PWhen defining an around callback remember to yield to the block, otherwise ;TI"it won't be executed:;T@o;;[I"around_create :log_status
;TI"
;TI"def log_status
;TI")  puts 'going to call the block...'
;TI"
  yield
;TI")  puts 'block successfully called.'
;TI"	end
;T;0o;
;[I"MYou can choose to have only specific callbacks by passing a hash to the ;TI"%+define_model_callbacks+ method.;T@o;;[I"=define_model_callbacks :create, only: [:after, :before]
;T;0o;
;[I"RWould only create the +after_create+ and +before_create+ callback methods in ;TI"your class.;T@o;
;[I"aNOTE: Calling the same callback multiple times will overwrite previous callback definitions.;T:
@fileI""lib/active_model/callbacks.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[[[I"ActiveSupport::Callbacks;To;;[;@X;0I""lib/active_model/callbacks.rb;T[[I"
class;T[[:public[[:protected[[:private[[I"
instance;T[[;[[I"define_model_callbacks;T@`[;[[;[[I"!_define_after_model_callback;T@`[I""_define_around_model_callback;T@`[I""_define_before_model_callback;T@`[[U:RDoc::Context::Section[i0o;;[;0;0[@XI"ActiveModel;TcRDoc::NormalModule