Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## Campaign.rb
  2. class Campaign < ActiveRecord::Base
  3.  
  4.   #relationships
  5.   has_one :banner, :class_name => "CampaignPicture", :as => :picturable, :dependent => :destroy
  6.   has_one :mail_banner, :class_name => "CampaignPicture", :as => :picturable, :dependent => :destroy
  7.  
  8.   accepts_nested_attributes_for :banner,  :reject_if => Proc.new {|attributes| attributes["data"].blank?}
  9.   accepts_nested_attributes_for :mail_banner, :reject_if => Proc.new {|attributes| attributes["data"].blank?}
  10.  
  11. end
  12.  
  13. ## Picture.rb
  14.  
  15. class Picture < ActiveRecord::Base
  16.   #acts_as_list :scope => :product
  17.  
  18.   belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
  19.   belongs_to :picturable, :polymorphic => true
  20.  
  21.   #validates_presence_of :content_type, :name, :width, :height
  22.  
  23.   has_attached_file .....
  24. end
  25.  
  26. ## schema picture table
  27.  
  28.  create_table "pictures", :force => true do |t|
  29.     t.integer  "author_id"
  30.     t.integer  "last_updater_id"
  31.     t.integer  "position",          :default => 1, :null => false
  32.     t.datetime "created_at"
  33.     t.datetime "updated_at"
  34.     t.integer  "picturable_id"
  35.     t.string   "data_file_name"
  36.     t.string   "data_content_type"
  37.     t.integer  "data_file_size"
  38.     t.datetime "data_updated_at"
  39.     t.string   "picturable_type"
  40.   end