Created
April 17, 2012 17:26
-
-
Save kurko/2407626 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 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