Skip to content

Instantly share code, notes, and snippets.

@lastk
Forked from kurko/gist:2407626
Created April 17, 2012 17:33
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 lastk/2407666 to your computer and use it in GitHub Desktop.
Save lastk/2407666 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.send_notification({login: "login",pass:"password"},@post.title)
end
end
end
class PostsController < ActionController::Base
def create
@context = PostCommitmentContext.new(params[:posts])
if @context.save
# redirect
# ...
end
end
end
class Twitter
def self.send_notification(user,text)
twitter = login(user.login,user.password) #dont mind about the names, ok?
twitter.send(text)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment