Skip to content

Instantly share code, notes, and snippets.

@jferris
Created July 3, 2012 18:32
Show Gist options
  • Select an option

  • Save jferris/3041674 to your computer and use it in GitHub Desktop.

Select an option

Save jferris/3041674 to your computer and use it in GitHub Desktop.
# create_table :posts do |table|
# table.string :title, :null => false, :default => ''
# table.string :body, :null => false, :default => ''
# table.string :published, :default => false
# end
class Post < ActiveRecord::Base
attr_accessible :title, :body
validates_presence_of :title
validates_presence_of :body, :if => :published?
def publish(attributes = {})
self.attributes = attributes
self.published = true
save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment