The Refactoring Today I used move method on the InvoiceController to move the #last_invoice_number to the Invoice model Before 1 2 3 4 5 6 7 8 class InvoiceController 'id DESC') unless last_invoice.nil? last_invoice.invoice_number else '-' end end endclass InvoiceController 'id DESC') unless last_invoice.nil? last_invoice.invoice_number else '-' end end end 1 2 3 class Invoice …
Category: Articles
Daily Refactor #80: Convert PaymentsController to REST Controller
The Refactoring Following up on yesterday’s refactoring, today I converted the PaymentsController to a REST controller. Before 1 2 3 4 5 6 7 8 9 10 11 # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources(:invoice, :collection => { :autocreate => :get, :autofill => :get }, :member => { :outstanding => :get }) end# config/routes.rb ActionController::Routing::Routes.draw do …
Daily Refactor #79: Convert Controller to REST Controller
The Refactoring Today’s refactoring took me quite a bit of setup work. I wanted to convert the InvoiceController to a REST controller in order to take advantage of all the built in helpers in Rails. I’m only going to show the routing changes I made, if want to dig deeper into the change there are …
Daily Refactor #78: Replace Data Value in InvoiceController with Object
The Refactoring Today’s refactoring cleans up some of the stubs left from last Friday. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 class InvoiceController < ApplicationController def autofill @autofill = Autofill.new_from_params(params[:autofill]) # TODO: should just access @autofill directly @p = @autofill.p …
Daily Refactor #77: Extract and Move Method in InvoiceController
Since I’m all hopped-up on white tea from an early morning meeting, this refactoring is a two in one. The Refactoring I used move method and extract method on the InvoiceController to move the business logic down into the model where it belongs. Before 1 2 3 4 5 6 7 8 9 10 11 …