
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.26 KB | hits: 12 | expires: Never
## Campaign.rb
class Campaign < ActiveRecord::Base
#relationships
has_one :banner, :class_name => "CampaignPicture", :as => :picturable, :dependent => :destroy
has_one :mail_banner, :class_name => "CampaignPicture", :as => :picturable, :dependent => :destroy
accepts_nested_attributes_for :banner, :reject_if => Proc.new {|attributes| attributes["data"].blank?}
accepts_nested_attributes_for :mail_banner, :reject_if => Proc.new {|attributes| attributes["data"].blank?}
end
## Picture.rb
class Picture < ActiveRecord::Base
#acts_as_list :scope => :product
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
belongs_to :picturable, :polymorphic => true
#validates_presence_of :content_type, :name, :width, :height
has_attached_file .....
end
## schema picture table
create_table "pictures", :force => true do |t|
t.integer "author_id"
t.integer "last_updater_id"
t.integer "position", :default => 1, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "picturable_id"
t.string "data_file_name"
t.string "data_content_type"
t.integer "data_file_size"
t.datetime "data_updated_at"
t.string "picturable_type"
end