Sha256: 039e1457a6e9af8f017b7a0ce37c519554cbe5bb52ff74525976835260d7ed15

Contents?: true

Size: 1.23 KB

Versions: 21

Compression:

Stored size: 1.23 KB

Contents

class Newsitem
  include Mongoid::Document
  include Mongoid::Timestamps

  belongs_to :site,    :optional => true
  belongs_to :tag,     :optional => true
  belongs_to :city,    :optional => true
  belongs_to :report,  :optional => true
  belongs_to :gallery, :optional => true
  belongs_to :video,   :optional => true

  has_one :photo

  field :name
  field :descr
  field :image_path
  field :link_path
  field :username
  field :partial_name

  field :weight,           :type => Integer, :default => 10
  field :n_upvotes,        :type => Integer, :default => 0
  field :n_downvotes,      :type => Integer, :default => 0
  field :upvoting_users,   :type => Array, :default => []
  field :downvoting_users, :type => Array, :default => []
  field :is_feature,       :type => Boolean, :default => false

  default_scope ->{ order_by({ :created_at => :desc }) }

  def self.from_params item
    n = Newsitem.new
    n.descr = item[:descr]
    n.username = item[:username]

    unless item[:report_id].blank?
      n.report = Report.find item[:report_id]
    end
    
    unless item[:gallery_id].blank?
      n.gallery = Gallery.find item[:gallery_id]
    end

    n.partial_name = item.partial_name unless item.partial_name.blank?

    return n
  end
  
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ish_models-0.0.33.74 lib/newsitem.rb
ish_models-0.0.33.73 lib/newsitem.rb
ish_models-0.0.33.71 lib/newsitem.rb
ish_models-0.0.33.70 lib/newsitem.rb
ish_models-0.0.33.69 lib/newsitem.rb
ish_models-0.0.33.68 lib/newsitem.rb
ish_models-0.0.33.67 lib/newsitem.rb
ish_models-0.0.33.66 lib/newsitem.rb
ish_models-0.0.33.65 lib/newsitem.rb
ish_models-0.0.33.64 lib/newsitem.rb
ish_models-0.0.33.63 lib/newsitem.rb
ish_models-0.0.33.62 lib/newsitem.rb
ish_models-0.0.33.61 lib/newsitem.rb
ish_models-0.0.33.60 lib/newsitem.rb
ish_models-0.0.33.59 lib/newsitem.rb
ish_models-0.0.33.58 lib/newsitem.rb
ish_models-0.0.33.57 lib/newsitem.rb
ish_models-0.0.33.56 lib/newsitem.rb
ish_models-0.0.33.55 lib/newsitem.rb
ish_models-0.0.33.54 lib/newsitem.rb