Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Forked from xhoy/liquid.html.liquid
Last active March 17, 2016 14:36
Show Gist options
  • Save tbuehlmann/f9b588d93813384fa6a3 to your computer and use it in GitHub Desktop.
Save tbuehlmann/f9b588d93813384fa6a3 to your computer and use it in GitHub Desktop.
# 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
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 %}
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
# 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