Skip to content
lyang edited this page Mar 16, 2013 · 3 revisions

Attributes

Each model has its own set of attributes.

Definition

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.

Serialization

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
Clone this wiki locally