= cheddargetter_client_rails The CheddarGetter rails client aims to tie the CheddarGetter API closely into ActiveRecord models. Much of the heavy lifting with the api itself is done through the cheddargetter_client_ruby gem. == Usage === In the model It can be very simple if you go with the default columns, ie: :customerCode => :id :email => :email, :firstName => :first_name, :lastName => :last_name, :planCode => :plan_code Then the declaration in the model is simply: class User < ActiveRecord::Base has_subscription end These are the only required columns however you can change their names locally very easily. class User < ActiveRecord::Base has_subscription :customerCode => :customer_code, :firstName => :name :lastName => :l_name :email => :business_email :planCode => "FREE_PLAN" end Note that the plan code can also take a string. The has_subscription will also takes additional key/values of items that appear both in your records for the user and CheddarGetter's records. For instance zip code is a common one. Here are others: :ccFirstName, :ccLastName, :ccExpiration, :ccNumber, :ccCountry, :ccAddress, :ccCity, :ccState, :company, :zip When the save is called on the subscription object or create is called on the user it grabs all shared attributes from your ActiveRecord record. === In the controller Make sure the subscription is always set on the user as some data may only exist there. class CreditCardsController < ApplicationController def edit @user = current_user end def update @user = current_user if @user.save_subscription(params[:cheddargetter_client_rails_subscription]) redirect_to edit_credit_card_path, :flash => {:success => 'Billing information updated'} else render 'edit' end end end Or in a user controller class UsersController < ApplicationController def new @user = User.new end def create @user = User.new @user.build_subscription(params[:cheddargetter_client_rails_subscription]) if @user.save redirect_to after_creation_path, :flash => {:success => 'User successfully created'} else render 'new' end end end The user save will take care of saving the subscription to CheddarGetter. === In the view Do something like this, if it is a user form use fields_for @user.subscription inside the user form. <%= form_for(@user.subscription, :url => credit_cards_path) do |subscription| %>