Module: DaisybillApi::Ext::CRUD::Create::InstanceMethods

Defined in:
lib/daisybill_api/ext/crud/create.rb

Instance Method Summary collapse

Instance Method Details

#createObject



100
101
102
# File 'lib/daisybill_api/ext/crud/create.rb', line 100

def create
  send_data :post, index_path
end

#saveObject

Creating or Updating a record

Creating a record

pt = DaisyBillApi::Models::Patient.new(
  billing_provider_id: 14,
  first_name: "Johnny",
  last_name: "Smith",
  ssn: "123456789",
  gender: "Male"
)

pt.save # => true

Updating a record

pt = DaisybillApi::Models::Patient.find(12) # => <DaisybillApi::Models::Patient id: 12...>

pt.telephone                # => "2138888888"

pt.telephone = "2137777777" # => "2137777777"

pt.telephone                # => "2137777777"

pt.save # => true

Inspecting errors

pt = DaisybillApi::Models::Patient.new(billing_provider_id: 14, first_name: "Johnny")

pt.save # => false

pt.errors.full_messages # => ["Last name can't be blank"]


91
92
93
94
95
96
97
# File 'lib/daisybill_api/ext/crud/create.rb', line 91

def save
  return create if new_record?
  return update if respond_to? :update
  message = "#save method is not supported for saved record"
  DaisybillApi.logger.error message
  raise NotImplementedError.new message
end