Skip to content

Instantly share code, notes, and snippets.

@mootpointer
Created May 6, 2015 02:28
Show Gist options
  • Save mootpointer/9b02b3fbe76ede1b2feb to your computer and use it in GitHub Desktop.
Save mootpointer/9b02b3fbe76ede1b2feb to your computer and use it in GitHub Desktop.
Service to update a user
require 'active_support/core_ext/hash/slice'
module MyCompany
module Services
class UpdateUser
attr_reader :user, :params
def initialize user, params
@user, @params = user, params
end
def allowed_params
[
"first_name", "last_name", "avatar_url", "email"
]
end
def cleaned_params
@params.slice(*allowed_params)
end
def call
user.update!(cleaned_params)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment