Module: Kushojin::ControllerMethods::Callback
- Defined in:
- lib/kushojin/controller_methods/callback.rb
Instance Method Summary collapse
-
#send_changes(callback = nil, **options) ⇒ Object
Send recorded changes.
Instance Method Details
#send_changes(callback = nil, **options) ⇒ Object
Send recorded changes.
class UsersController < ApplicationController
send_changes
def create
User.create(user_params)
end
def update
User.find(params[:id]).update(user_params)
end
def destroy
User.find(params[:id]).destroy
end
private
def user_params
params.require(:user).permit(:name)
end
end
You can pass in a class or an instance to change behavior of the callback.
class CustomCallback < Kushojin::ControllerMethods::SendChangeCallback
# Must respond to around.
def around(controller)
# Do something
super
end
end
class UsersController < ApplicationController
send_changes CustomCallback.new
end
Options
-
only- Send changes only for this action. -
except- Send changes for all actions except this action.
47 48 49 50 |
# File 'lib/kushojin/controller_methods/callback.rb', line 47 def send_changes(callback = nil, **) callback ||= Kushojin::ControllerMethods::SendChangeCallback.new around_action callback, end |