Skip to content

Instantly share code, notes, and snippets.

@talum
Created May 28, 2019 16:00
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 talum/540feec39401a1fc584094d2b97e5179 to your computer and use it in GitHub Desktop.
Save talum/540feec39401a1fc584094d2b97e5179 to your computer and use it in GitHub Desktop.
Invoices Controller 2
class InvoicesController < ApplicationController
  def update
  # The developer reasons that adding a timestamp to the params to
  # leverage the existing code will do the trick
  if params[:cancel]
  invoice_params[:closed_at] = Time.current
  end
  invoice = Invoice.find(params[:id])
  invoice.update!(invoice_params) # what's in these params?!?
  redirect_to invoice
  end
  private
  def invoice_params
  params.require(:invoice).permit(:amount_due, :closed_at, :due_date,
   :scheduled_send_date, :paid_at)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment