Sha256: 29e0c766e4cbc87a7a5e7a13687adfb0c6863826114f714c9d95cf3ce4e32c1b
Contents?: true
Size: 957 Bytes
Versions: 8
Compression:
Stored size: 957 Bytes
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: pap )} def list_title name end def preferred? parent printables.where(printable: parent).first.preferred? end def prefer parent parent.printables.each{ |p| p.update_columns(preferred: false) } 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
8 entries across 8 versions & 1 rubygems