-
-
Save tbuehlmann/f9b588d93813384fa6a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/drops/invoice_drop.rb | |
class InvoiceDrop < Liquid::Drop | |
delegate :days_late, :priceinbtw, :print_date, :id, :late, :unpayed, to: :invoice | |
attr_reader :invoice | |
def initialize(invoice) | |
@invoice = invoice | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOES NOT WORK: | |
{% for invoice in relation.invoices.late %} | |
<tr> | |
<td>{{invoice.id}}</td> | |
<td>{{invoice.print_date}}</td> | |
<td>{{invoice.days_late}}</td> | |
<td>{{invoice.priceinbtw}}</td> | |
</tr> | |
{% endfor %} | |
DOES WORK | |
{% for invoice in relation.invoices %} | |
<tr> | |
<td>{{invoice.id}}</td> | |
<td>{{invoice.print_date}}</td> | |
<td>{{invoice.days_late}}</td> | |
<td>{{invoice.priceinbtw}}</td> | |
</tr> | |
{% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Relation < ActiveRecord::Base | |
has_many :invoices | |
def to_liquid | |
RelationDrop.new(self) | |
end | |
end | |
class Invoice < ActiveRecord::Base | |
scope :late, -> {unpayed.where("print_date < ? ", (Time.now-APP_CONFIG['betaalinformatie']['termijn'].days))} | |
liquid_methods :days_late, :priceinbtw, :print_date, :id, :late, :unpayed | |
def to_liquid | |
InvoiceDrop.new(self) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/drops/relation_drop.rb | |
class RelationDrop < Liquid::Drop | |
delegate :full_name, :letter_head, to: :relation | |
attr_reader :relation | |
def initialize(relation) | |
@relation = relation | |
end | |
def invoices | |
relation.invoices.map(&:to_liquid) | |
end | |
def late_invoices | |
relation.invoices.late.map(&:to_liquid) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment