Re: Saving dates

Stewart
2006-12-14T04:30:16Z

askegg wrote:
> Model and schema please...

# == Schema Information
# Schema version: 57
#
# Table name: exhibitions
#
#  id                :integer(11)   not null, primary key
#  name              :string(255)
#  subtitle          :string(255)
#  short_description :string(255)
#  description       :string(255)
#  curator           :string(255)
#  artists           :string(255)
#  url               :string(255)
#  image             :string(255)   default(/exhibition/image/1_0.gif)
#  catalogue         :string(255)
#  admission_price   :text
#  open_date         :date
#  close_date        :date
#  user_id           :integer(11)
#  gallery_id        :integer(11)

class Exhibition < ActiveRecord::Base
  has_one :advertisement
  belongs_to :user
  belongs_to :image
  belongs_to :gallery
  belongs_to :listing_status
  has_and_belongs_to_many :organisations
  has_and_belongs_to_many :artists
  has_and_belongs_to_many :curators
  has_and_belongs_to_many :festivals
  has_and_belongs_to_many :tags
  has_one :feature_exhibition
  has_many :weeks

validates_presence_of :name, :short_description, :subtitle, :on =>
:create
#file_column :image

  def self.find_exhibitions_currently_on
   find(:all,
   :conditions => "(open_date < now()) && (close_date >
now())",
   :order => "close_date desc"
   )
  end

  def self.find_exhibitions_closed
     find(:all,
        :conditions => "close_date < now()",
       :order => "close_date")
  end


  def self.find_exhibitions_coming_up
     find(:all,
        :conditions => "open_date > now()",
       :order => "open_date")
  end
end