Skip to content

Instantly share code, notes, and snippets.

@kyprifog
Created March 4, 2016 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyprifog/b0d3de5d9e74506029c8 to your computer and use it in GitHub Desktop.
Save kyprifog/b0d3de5d9e74506029c8 to your computer and use it in GitHub Desktop.
Strong Parameters in Service Object
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