Skip to content

Instantly share code, notes, and snippets.

@andrebautista
Created October 25, 2013 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrebautista/7148660 to your computer and use it in GitHub Desktop.
Save andrebautista/7148660 to your computer and use it in GitHub Desktop.
class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true
validates :content, presence: true
validates :author_email, presence: true
validates :author, presence: true
end
class Project < ActiveRecord::Base
attr_accessible :name, :technologies_used
validates :technologies_used, presence: true
validates :name, length: { in: 4..255 }
has_many :comments, as: :commentable
end
class Post < ActiveRecord::Base
belongs_to :author, class_name: "User"
has_many :comments, as: :commentable
scope :published, where(published: true)
def publish!
published = true
save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment