Sha256: 4e7e7be13e44d66c9aa4dfeaf5b6560e861a7bf3adb3c6b439fdeb9120293a51

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'string'
class Gallery < AppModel2

  belongs_to :site
  validates :site, :presence => true

  belongs_to :user
  validates :user, :presence => true
  field :username, :type => String
  
  field :name, :type => String
  validates :name, :uniqueness => true # , :allow_nil => false

  field :galleryname, :type => String
  validates :galleryname, :uniqueness => true # , :allow_nil => false

  field :subhead, :type => String
  field :descr, :type => String
  field :lang, :type => String, :default => 'en'

  # not necessary because AppModel2
  # default_scope ->{ where( :is_public => true, :is_trash => false ).order_by( :created_at => :desc ) }

  has_many :photos

  belongs_to :tag
  belongs_to :city
  belongs_to :venue
    
  set_callback(:create, :before) do |doc|
    doc.username = doc.user.username
    doc.galleryname = doc.name.to_simple_string

    # for the homepage
    if doc.is_public && doc.site
      n = Newsitem.new {}
      n.gallery = doc
      n.username = doc.user.username
      sites = Site.where( :domain => doc.site.domain )
      sites.each do |site|
        site.newsitems << n
        flag = site.save
        if !flag
          puts! site.errors
        end
      end
    end
  end

  # @deprecated, use Gallery::ACTIONS
  def self.actions
    [ 'show_mini', 'show_long', 'show' ]
  end
  ACTIONS = [ 'show_mini', 'show_long', 'show' ]

end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
ish_models-0.0.3 lib/gallery.rb
ish_lib-0.0.8 app/models/gallery.rb
ish_lib_engine-0.0.5 app/models/gallery.rb
ish_lib-0.0.3 app/models/gallery.rb