Skip to content

Instantly share code, notes, and snippets.

@dannymcc
Created August 1, 2012 08:34
Show Gist options
  • Select an option

  • Save dannymcc/3225047 to your computer and use it in GitHub Desktop.

Select an option

Save dannymcc/3225047 to your computer and use it in GitHub Desktop.
Mark invoice as Paid
class InvoicesController < InheritedResources::Base
custom_actions :resource => :mark_paid
def show
show! do |format|
format.html
format.pdf do
send_data(@invoice.render_pdf, :filename => "Invoice #{@invoice.id}.pdf", :type => "application/pdf", :disposition => "inline")
end
end
end
def create
create! { invoices_url }
end
def mark_paid
mark_paid! do
if !@invoice.paid?
@invoice.update_attribute(:paid_at, Time.now)
end
redirect_to @invoice and return
end
end
end
<% if @invoice.paid? %>
<%= @invoice.paid_at %>
<% else %>
Unpaid (<%= link_to "Mark as Paid", mark_paid_invoice_url(@invoice), :method => :put %>)
<% end %>
PaydayExample::Application.routes.draw do
resources :invoices do
member do
put 'mark_paid'
end
resources :line_items
end
root :to => "invoices#index"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment