diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 3bc9292..c8f998f 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -18,9 +18,7 @@ class CustomersController < ApplicationController # display a list of all customers def index - Customer.without_callback(:initialize, :after, :pull) do - @customers = Customer.paginate(:page => params[:page]) - end + @customers = Customer.paginate(:page => params[:page]) end def new diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb index 6c280f7..44e071c 100644 --- a/app/controllers/vehicles_controller.rb +++ b/app/controllers/vehicles_controller.rb @@ -24,9 +24,7 @@ class VehiclesController < ApplicationController # return an HTML form for creating a new vehicle def new @vehicle = Vehicle.new - Customer.without_callback(:initialize, :after, :pull) do - @customers = Customer.all.order(:name) - end + @customers = Customer.all.order(:name) end # create a new vehicle @@ -55,9 +53,7 @@ class VehiclesController < ApplicationController begin @vehicle = Vehicle.find_by_id(params[:id]) @customer = @vehicle.customer.id - Customer.without_callback(:initialize, :after, :pull) do - @customers = Customer.all.order(:name) - end + @customers = Customer.all.order(:name) rescue ActiveRecord::RecordNotFound render_404 end diff --git a/app/models/customer.rb b/app/models/customer.rb index 71942c3..f52c562 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -19,16 +19,9 @@ class Customer < ActiveRecord::Base validates_presence_of :id, :name - after_initialize :pull self.primary_key = :id - def all - without_callback(:initialize, :after, :pull) do - super - end - end - # returns a human readable string def to_s return name @@ -36,6 +29,7 @@ class Customer < ActiveRecord::Base # returns the customer's email def email + pull unless @details begin return @details.email_address.address rescue @@ -45,6 +39,7 @@ class Customer < ActiveRecord::Base # returns the customer's primary phone def primary_phone + pull unless @details begin return @details.primary_phone.free_form_number rescue @@ -54,6 +49,7 @@ class Customer < ActiveRecord::Base # Updates the customer's primary phone number def primary_phone=(n) + pull unless @details Quickbooks::Model::TelephoneNumber.new pn.free_form_number = n @details.primary_phone = pn @@ -61,6 +57,7 @@ class Customer < ActiveRecord::Base # returns the customer's mobile phone def mobile_phone + pull unless @details begin return @details.mobile_phone.free_form_number rescue @@ -70,6 +67,7 @@ class Customer < ActiveRecord::Base # Updates the custome's mobile phone number def mobile_phone=(n) + pull unless @details Quickbooks::Model::TelephoneNumber.new pn.free_form_number = n @details.mobile_phone = pn @@ -77,12 +75,14 @@ class Customer < ActiveRecord::Base # Updates Both local DB name & QBO display_name def name=(s) + pull unless @details display_name = s super end # Magic Method def method_missing(name, *arguments) + pull unless @details value = arguments[0] name = name.to_s @@ -122,12 +122,6 @@ class Customer < ActiveRecord::Base #where.not(customers.map(&:id)).destroy_all end - def self.without_callback(*args, &block) - Customer.skip_callback(*args) - yield - Customer.set_callback(*args) - end - # Push the updates def save_with_push save_without_push