-
Notifications
You must be signed in to change notification settings - Fork 22
Attributes
lyang edited this page Mar 16, 2013
·
3 revisions
Each model has its own set of attributes.
Some of those can be used only in create, some can be updated, and others are readonly. Take BraintreeRails::Customer
for example:
:create => [:company, :custom_fields, :email, :fax, :first_name, :id, :last_name, :options, :phone, :website],
:update => [:company, :custom_fields, :email, :fax, :first_name, :last_name, :options, :phone, :website],
:readonly => [:created_at, :updated_at]
You can assign id
when creating a customer, but you can't update it.
created_at
and updated_at
are readonly attributes.
So, when updating a customer object, id
, created_at
and updated_at
will be ignored.
BraintreeRails models implements the ActiveRecord
serialization interface. So you can do the following:
customer.attributes # => returns a hash with all the attributes and their current values
customer.as_json # => returns a hash with root key being the name of the model
customer.to_xml # => returns xml representation of the customer object