All pastes #246507 Raw Edit

Mine

public ruby v1 · immutable
#246507 ·published 2006-11-12 08:11 UTC
rendered paste body
class Website < ActiveRecord::Base        file_column :image_path, :magic => {                :geometry => "200x150"        }        belongs_to :user        has_many :comments        has_many :ratings        validates_presence_of :title,                :message => "You must supply a title for this website."        validates_presence_of :url,                :message => "You must supply a url for this website."        def rating                rating = 0                r = self.ratings.find(:all)                r.each { |k| rating += k[:rating] }                l = r.length > 0 ? r.length : 1                rating        end        def next                self.class.find_approved :first, :conditions => ["id > ?", self[:id]]        end        def prev                website = self.class.find_approved :first, :conditions => ["id < ?", self[:id]], :order => "id DESC"        end        def self.find_approved(*args)                with_scope(:find => { :conditions => "is_approved <> 0" }) do                        find(*args)                end        endend