Tag: ruby

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 …

Read more

Daily Refactor #76: Replace Temp with Query in Invoice#fully_paid?

The Refactoring Since I refactored Invoice#outstanding yesterday, I can now build on that to refactor Invoice#fully_paid?. Before 1 2 3 class Invoice = self.amount end endclass Invoice = self.amount end end After 1 2 3 4 5 class Invoice < ActiveRecord::Base def fully_paid? outstanding <= 0 end endclass Invoice < ActiveRecord::Base def fully_paid? outstanding <= …

Read more