2013-03-28 04:06:10 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
class Qa
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Mongoid::MultiParameterAttributes
|
2013-04-26 03:18:57 +00:00
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
include OrbitModel::LanguageRestrict
|
|
|
|
include OrbitModel::Status
|
|
|
|
include OrbitTag::Taggable
|
2013-08-20 07:54:56 +00:00
|
|
|
include OrbitCategory::Categorizable
|
2013-03-28 04:06:10 +00:00
|
|
|
|
2013-03-28 07:05:52 +00:00
|
|
|
field :title, localize: true
|
2013-03-28 04:06:10 +00:00
|
|
|
field :answer, localize: true
|
|
|
|
|
|
|
|
field :create_user_id
|
|
|
|
field :update_user_id
|
|
|
|
|
|
|
|
has_many :qa_links, :autosave => true, :dependent => :destroy
|
|
|
|
has_many :qa_files, :autosave => true, :dependent => :destroy
|
|
|
|
|
|
|
|
accepts_nested_attributes_for :qa_files, :allow_destroy => true
|
|
|
|
accepts_nested_attributes_for :qa_links, :allow_destroy => true
|
|
|
|
|
2013-11-08 09:38:05 +00:00
|
|
|
# belongs_to :qa_category
|
2013-03-28 04:06:10 +00:00
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
before_save :clean_values
|
2013-03-28 04:06:10 +00:00
|
|
|
|
2013-03-28 07:05:52 +00:00
|
|
|
validates :title, :at_least_one => true
|
2013-03-28 04:06:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def self.search( category_id = nil )
|
|
|
|
|
|
|
|
if category_id.to_s.size > 0
|
|
|
|
|
|
|
|
find(:all, :conditions => {qa_category_id: category_id}).desc( :is_top, :title )
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
find(:all).desc( :is_top, :title)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.widget_datas
|
|
|
|
|
|
|
|
where( :is_hidden => false ).desc(:is_top, :created_at)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def qa_category_with_title
|
2013-09-14 03:54:35 +00:00
|
|
|
self.category.title
|
2013-03-28 04:06:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def clean_values
|
|
|
|
self.qa_links.each do |link|
|
|
|
|
link.delete if link.url.blank? && link.title.blank?
|
|
|
|
end
|
2013-05-03 04:11:48 +00:00
|
|
|
self.tagged_ids.delete('')
|
2013-03-28 04:06:10 +00:00
|
|
|
end
|
|
|
|
|
2013-08-19 02:12:28 +00:00
|
|
|
paginates_per 10
|
2013-03-28 04:06:10 +00:00
|
|
|
end
|