Created
August 1, 2012 08:34
-
-
Save dannymcc/3225047 to your computer and use it in GitHub Desktop.
Mark invoice as Paid
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 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 |
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
| <% if @invoice.paid? %> | |
| <%= @invoice.paid_at %> | |
| <% else %> | |
| Unpaid (<%= link_to "Mark as Paid", mark_paid_invoice_url(@invoice), :method => :put %>) | |
| <% 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
| 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