Sha256: 062dd0f1d503522b36cfc387dcab0332a0c2d5b292a7767bf7bb0193ecf833c4
Contents?: true
Size: 1.07 KB
Versions: 15
Compression:
Stored size: 1.07 KB
Contents
class OxPrinter < AbstractResource self.table_name = 'printers' establish_connection ((Rails.env=="development") ? :dev_oxen_tables : :oxen_tables ) attr_accessor :snap_shot has_paper_trail has_many :printables, foreign_key: 'printer_id', dependent: :destroy has_many :users, through: :printables, source: :printable, source_type: 'User' validates :name, presence: true scope :active, -> { where(active: true) } scope :preferred_printer, ->{ where("printables.preferred=1")} scope :on_paper, -> (pap){ where("paper LIKE :pap", pap: "%#{pap}%")} def list_title name end def _ref paper end def preferred? parent printables.where(printable: parent).first.preferred? end def prefer parent ps = parent.printers.preferred_printer.on_paper(self.paper) parent.printables.each{ |p| p.update_columns(preferred: false) if ps.include? p.printer } printables.where(printable: parent).first.update_columns( preferred: true ) end def defer parent printables.where(printable: parent).first.update_columns( preferred: false ) end end
Version data entries
15 entries across 15 versions & 1 rubygems