class Project < ActiveRecord::Base<br> has_and_belongs_to_many :skills<br> belongs_to :employment<br> belongs_to :education<br> belongs_to :publication<br> <br> has_attached_file :image, <br> :styles => { :large => ">", :thumbnail => "125x125#" }, :default_url => '/images/missing_:style.png', :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => ":image/:id/:style.:extension" accepts_nested_attributes_for :skills, :employment, :education, :publication validates_presence_of :name def related my_projects = [] if self.employment my_projects = my_projects | self.employment.projects end if self.education my_projects = my_projects | self.education.projects end if self.publication my_projects = my_projects | self.publication.projects end if self.skills.any? and my_projects.empty? self.skills.each do |skill| my_projects = my_projects | skill.projects end end my_projects.uniq.reject{ |p| p == self } end def before_create if self.permalink.nil? self.permalink = self.name.downcase.strip.gsub(/[^A-Za-z0-9]+/, ' ').gsub(/\ +/, '-') end end end
Saturday, June 5, 2010
Test Code
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment