Skip to content

Instantly share code, notes, and snippets.

@cnix
Created December 19, 2008 00:10
Show Gist options
  • Save cnix/37724 to your computer and use it in GitHub Desktop.
Save cnix/37724 to your computer and use it in GitHub Desktop.
class PostsController < ApplicationController
def create
@post = Post.new(params[:post])
if @post.save
tweet(@post)
flash[:notice] = 'Post was successfully created.'
redirect_to manage_posts_path
else
render :action => 'new'
end
end
private
def tweet(post)
if post.to_twitter?
# do stuff
end
end
end
class Post < ActiveRecord::Base
attr_accessor :to_twitter
alias :to_twitter? :to_twitter
end
#
# in the view
<%= check_box :post, :to_twitter %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment