Created
May 6, 2015 02:28
-
-
Save mootpointer/9b02b3fbe76ede1b2feb to your computer and use it in GitHub Desktop.
Service to update a user
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
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