Add this line to your application’s Gemfile:
$ bundle add amazing-activist
Or install it yourself as:
$ gem install amazing-activist
class ApplicationActivity < AmazingActivist::Base
end
class OnboardingActivity < ApplicationActivity
def call
user = User.new(params)
return failure(:invalid_params, user: user) unless user.save
success(user)
end
end
class UsersController < ApplicationController
def create
case OnboardingActivity.call(**params.require(:user).permit(:password))
in success: user
redirect_to user_bashboard_url(user)
in failure: :invalid_params, context: { user: user }
@user = user
render :new
else
head :bad_request
end
end
end
This library aims to support and is tested against:
-
-
MRI 3.0.x
-
MRI 3.1.x
-
MRI 3.2.x
-
MRI 3.3.x
-
MRI 3.4.x
-
If something doesn’t work on one of these versions, it’s a bug.
This library may inadvertently work (or seem to work) on other Ruby versions, however support will only be provided for the versions listed above.