Skip to content

Instantly share code, notes, and snippets.

@kurko
Created April 17, 2012 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kurko/2407626 to your computer and use it in GitHub Desktop.
Save kurko/2407626 to your computer and use it in GitHub Desktop.
class PostCommitmentContext
def initialize(params)
@params = params
end
def save
@post = Post.new(@params)
if @post.save
# @post é ActiveRecord, então não há o que extender mesmo porque ActiveRecord já está encruado
@twitter = Twitter.login("username", "password")
@twitter.extend Twitterer
@twitter.tweet @post.body
end
end
end
class PostsController < ActionController::Base
def create
@context = PostCommitmentContext.new(params[:posts])
if @context.save
# redirect
# ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment