Skip to content

Instantly share code, notes, and snippets.

@knaveofdiamonds
Forked from jccarbonfive/gist:1575869
Created January 12, 2012 16:42
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save knaveofdiamonds/1601522 to your computer and use it in GitHub Desktop.
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