Skip to content

Instantly share code, notes, and snippets.

@rajeevkannav
Created December 9, 2013 12:46
Show Gist options
  • Save rajeevkannav/7871761 to your computer and use it in GitHub Desktop.
Save rajeevkannav/7871761 to your computer and use it in GitHub Desktop.
#Fixme
class Post < ActiveRecord::Base
#Validations
validates :data, presence: true, length: {in: 6..200}
validates :source, presence: true, length: {in: 3..200}
validates :state, presence: true, length: {in: 0..20}
#Callbacks
after_save :padded_data
#Associations
has_many :subcategories, class_name: 'Category'
has_one :category, :through => :subcategories
private
def padded_data
#FixME: write logic here
end
end
class Category < ActiveRecord::Base
#Validations
validates :name, presence: true, length: {in: 6..200}
validates :state, presence: true, length: {in: 0..20}
#Association
belongs_to :category
has_many :subcategories, class_name: 'Category', dependent: :destroy
has_many :posts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment