Created
July 8, 2009 23:42
-
-
Save mileszs/143304 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # == Schema Information | |
| # | |
| # Table name: rfqs | |
| # | |
| # id :integer not null, primary key | |
| # title :string(100) | |
| # quantity :integer | |
| # trim_size_id :integer | |
| # binding_type_id :integer | |
| # pages :integer | |
| # dust_jacket :boolean | |
| # finish_id :integer | |
| # binding_notes :text | |
| # paper_type_id :integer | |
| # paper_weight :integer | |
| # board :string(10) | |
| # board_front :boolean | |
| # board_back :boolean | |
| # file_delivery_method_id :integer | |
| # file_delivery_notes :text | |
| # web_proofs :boolean | |
| # digital_proofs :integer | |
| # dummies :integer | |
| # proof_notes :text | |
| # recommended_packaging :boolean | |
| # packaging_notes :text | |
| # delivery_method_id :integer | |
| # files_ready_on :datetime | |
| # created_at :datetime | |
| # updated_at :datetime | |
| # notes :text | |
| # | |
| class Rfq < ActiveRecord::Base | |
| validates_presence_of :title | |
| validates_each :file_delivery_notes do |record, attr, value| | |
| if record.file_delivery_method =~ /other/i && value.blank? | |
| record.errors.add attr, 'should be filled if File Delivery Method is \'Other\'' | |
| end | |
| end | |
| belongs_to :organization | |
| belongs_to :address | |
| belongs_to :creator, :class_name => 'User', :foreign_key => :creator_id | |
| has_many :uploads | |
| has_many :quotes | |
| def self.creatable_by?(user) | |
| true | |
| end | |
| def editable_by?(user) | |
| self.organization_id == user.organization_id | |
| end | |
| def notify_admin | |
| AdminMailer.deliver_rfq_notification(self) | |
| end | |
| def display_name | |
| "#{self.title} #{self.pages || '?'}pp x #{self.quantity}" | |
| end | |
| def org | |
| return nil if self.organization.nil? | |
| self.organization.name | |
| end | |
| def accepted? | |
| Quote.find(:first, :conditions => ['rfq_id = ? AND accepted_at IS NOT NULL', self.id]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment