Skip to content
This repository

Renaming an attribute

When calling a method, association or whatever you want to add to the template, you always can change the name of the attribute that will be rendered in the response, by passing an :as option.

class User < ActiveRecord::Base


  api_accessible :public do |t|
    t.add :first_name
    t.add :last_name, :as => :family_name


Which would result in a JSON response like this:

  "user": {
    "first_name": "Luke",
    "family_name": "Skywalker"
Something went wrong with that request. Please try again.