daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest May 16th, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Exhibit < ActiveRecord::Base
  2.  
  3.   acts_as_list
  4.  
  5.   has_many :images, :through => :image_associations
  6.   has_many :image_associations, :as => :associable, :dependent => :destroy
  7.   has_many :calendar_items, :as => :calendarable, :dependent => :destroy
  8.   belongs_to :created_by, :class_name => "User", :foreign_key => "created_by"
  9.   belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by"
  10.  
  11.   def begin_date_string
  12.     self.begin_date ? self.begin_date.to_s(:standard) : Time.now.to_s(:standard)
  13.   end
  14.  
  15.   def begin_date_string=(date)
  16.     self.begin_date = Date.parse(date)
  17.   end
  18.  
  19.   def end_date_string
  20.     self.end_date ? self.end_date.to_s(:standard) : Time.now.to_s(:standard)
  21.   end
  22.  
  23.   def end_date_string=(date)
  24.     self.end_date = Date.parse(date)
  25.   end
  26.  
  27.   def image_attributes=(attributes)
  28.     if image = Image.create(attributes)
  29.       self.image_associations.create(:image => image)
  30.     end
  31.   end
  32.  
  33.   def calendar_item_attributes=(attributes)
  34.     calendar_item = self.calendar_items.build
  35.     calendar_item.update_attributes(attributes)
  36.   end
  37.  
  38. end
RAW Paste Data
Top