bigdir/app/models/softapplication.rb

37 lines
1.2 KiB
Ruby
Raw Normal View History

class Softapplication < ActiveRecord::Base
attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id, :application_developers, :deposit_project_url, :deposit_project
2014-04-09 09:25:24 +08:00
acts_as_attachable
2014-04-21 15:41:51 +08:00
seems_rateable :allow_update => true, :dimensions => :quality
2014-04-18 16:35:48 +08:00
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :contesting_softapplications, :dependent => :destroy
#has_many :projecting_softapplications, :dependent => :destroy
belongs_to :user
belongs_to :project
has_many :contests, :through => :contesting_softapplications
belongs_to :project
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
else
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
end
end
def set_commit(commit)
self.update_attribute(:commit, commit)
end
def editable_by? usr
usr.admin? || self.user == usr
end
def destroyable_by? usr
self.user == usr || usr.admin?
end
end