Skip to content

Instantly share code, notes, and snippets.

@spacecowb0y
Last active December 11, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spacecowb0y/4637001 to your computer and use it in GitHub Desktop.
Save spacecowb0y/4637001 to your computer and use it in GitHub Desktop.
Sexy methods for AR objects.
def unread_comments
readable_comments.delete_if {|c| c.created_at < c.discussion.assignments.find_by_user_id(id).updated_at }
end
def create_new_invoice!
invoice = invoices.build
order_item_options.delete_if{ |o| o.price == 0 }.map{ |o| invoice.invoice_lines.build(:order_item_id => o.order_item.id, :description => o.order_item.name, :unit_price => o.price) }
invoice.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment