Created
March 4, 2016 19:26
-
-
Save kyprifog/b0d3de5d9e74506029c8 to your computer and use it in GitHub Desktop.
Strong Parameters in Service Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateUser | |
def initialize(params) | |
@params = user_params(params) | |
@user = User.new(@params) | |
end | |
def perform | |
ActiveRecord::Base.transaction do | |
# do stuff | |
@user.save! | |
end | |
end | |
def user_params(params) | |
params = ActionController::Parameters.new(params) | |
params.permit(:first_name, :last_name, :email, :password, :company, :phone) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment