Ruby on Rails Model

Ruby code posted by Padde
created at 19 Jul 16:57

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Group < ActiveRecord::Base
  has_many :memberships, :dependent => :destroy
  has_many :people, :through => :memberships
  accepts_nested_attributes_for :memberships, :allow_destroy => true
  
  has_many :images, :as => :imageable, :dependent => :destroy
  accepts_nested_attributes_for :images, :allow_destroy => true
  
  validates_associated :memberships, :images
  
  belongs_to :user
  
  validates_presence_of :name, :description
  validates_format_of :website_url, :with => %r{^((http|https)://)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?/.*)?$|^$}ix, :allow_nil => true
  
  attr_accessible :name, :description, :website_url, :images_attributes, :memberships_attributes
  
  scope :asc, order('name')
end
749 Bytes in 2 ms with coderay