Last active
August 29, 2015 14:02
-
-
Save tbuehlmann/283af18112a513b099f4 to your computer and use it in GitHub Desktop.
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 UserCreator | |
def initialize(listener) | |
@listener = listener | |
end | |
def create(attributes) | |
user = User.new(attributes) | |
if user.save | |
# send email | |
# do things | |
@listener.creation_successful | |
else | |
@listener.creation_unsuccessful(user) | |
end | |
end | |
end |
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 UsersController < ApplicationController | |
def create | |
user_creater = UserCreator.new(self) | |
user_creater.create(user_params) | |
end | |
def creation_successful | |
redirect_to users_url, notice: 'Yay.' | |
end | |
def creation_unsuccessful(user) | |
@user = user | |
render :new | |
end | |
hide_action :creation_successful, :creation_unsuccessful | |
private | |
def user_params | |
params.require(:user).permit(:foo, :bar) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment