Sha256: 6224f86869ebe4a08aadde4e0048d6d23c56e28fa0195c09bcfb956d6e59c7c9
Contents?: true
Size: 1.63 KB
Versions: 3
Compression:
Stored size: 1.63 KB
Contents
# -*- encoding: utf-8 -*- class Answer < ActiveRecord::Base default_scope { order('answers.id ASC') } #scope :public_answers, where(:shared => true) #scope :private_answers, where(:shared => false) belongs_to :user, validate: true belongs_to :question, validate: true has_many :answer_has_items, dependent: :destroy has_many :items, through: :answer_has_items after_save :save_questions before_save :add_items validates_associated :user, :question validates_presence_of :user, :question, :body validate :check_url_list paginates_per 10 def save_questions question.save end def add_items item_list = item_identifier_list.to_s.strip.split.map{|i| Item.where(item_identifier: i).first}.compact.uniq url_list = add_urls self.items = item_list + url_list end def add_urls list = url_list.to_s.strip.split.map{|u| Manifestation.where(:access_address => Addressable::URI.parse(u).normalize.to_s).first}.compact.map{|m| m.web_item}.compact.uniq end def check_url_list url_list.to_s.strip.split.each do |url| errors.add(:url_list) unless Addressable::URI.parse(url).host end end end # == Schema Information # # Table name: answers # # id :integer not null, primary key # user_id :integer not null # question_id :integer not null # body :text # created_at :datetime # updated_at :datetime # deleted_at :datetime # shared :boolean default(TRUE), not null # state :string # item_identifier_list :text # url_list :text #
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
enju_question-0.2.0 | app/models/answer.rb |
enju_question-0.2.0.beta.4 | app/models/answer.rb |
enju_question-0.2.0.beta.3 | app/models/answer.rb |