Skip to content

Instantly share code, notes, and snippets.

@guipdutra
Created July 9, 2013 17:48
Show Gist options
  • Save guipdutra/5959524 to your computer and use it in GitHub Desktop.
Save guipdutra/5959524 to your computer and use it in GitHub Desktop.
class BudgetAllocationCapability < Accounting::Model
attr_accessible :amount, :capability_id
attr_modal :capability_description
belongs_to :budget_allocation
belongs_to :capability
delegate :description, :to => :capability, :allow_nil => true, :prefix => true
validates :capability, :amount, :presence => true
validates :amount, :numericality => { :greater_than => 0.0 }
scope :by_budget_allocation_id, lambda { |id|
joins { budget_allocation }.where { budget_allocation_id.eq(id) } if id.present?
}
orderize :id
def self.filter(options)
query = scoped
if options[:capability_description].present?
query = query.joins { capability }
query = query.where { capability.description.like("%#{options[:capability_description]}%") }
end
query
end
def self.by_capability(capability_filter)
joins { capability }.
where { capability.id.eq(capability_filter.id)}
end
def updateable?
capability_id_changed?
end
def destroyable?
false
end
def to_s
"#{capability.to_s}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment