Skip to content
Create a gist now

Instantly share code, notes, and snippets.

class UsersController < ApplicationController
def create
respond_to do |format|
format.html do
@user = UserService.create(params[:user], true)
redirect_to @user
end
format.json do
@user = UserService.create(params[:user], false)
render :json => @user,
:status => :created,
:location => @user
end
end
end
end
class UserService
def self.create(attributes, welcome)
user = User.new(attributes)
user.save
EmailService.welcome_email(user) if welcome
user
end
end
class EmailService
def self.welcome_email(user)
email = UserMailer.welcome_email user
email.deliver
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.