Skip to content

Instantly share code, notes, and snippets.

@bernd
Created November 21, 2012 08:15
Show Gist options
  • Save bernd/4123764 to your computer and use it in GitHub Desktop.
Save bernd/4123764 to your computer and use it in GitHub Desktop.
class Controller
def create
creator = OrganizationCreator.new(FeedWriter.new(self))
creator.create_for(current_user, params[:organization])
end
def create_organization_succeeded(organization)
redirect_to '/foo', :notice => 'success'
end
end
class FeedWriter < Struct.new(:listener)
def create_organization_succeeded(organization)
ActivityFeed.create!(:message => 'Organization created...')
listener.create_organization_succeeded(organization)
end
end
class OrganizationCreator < Struct.new(:listener)
def create_for(user, attributes)
# ...
if organization.save
# ...
listener.create_organization_succeeded(organization)
else
# ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment