-
Notifications
You must be signed in to change notification settings - Fork 67
Extending an existing api template
fabrik42 edited this page Apr 20, 2011
·
2 revisions
To keep your api templates DRY, you can create a new template based on another template of the same model.
class User < ActiveRecord::Base
acts_as_api
api_accessible :only_names do |t|
t.add :first_name
t.add :last_name
end
api_accessible :age_and_names, :extend => :only_names do |t|
t.add :age
end
endThe api template age_and_names extends the template only_names so it will contain the attributes first_name, last_name and age.
It is also possible to remove attributes that were inherited from the api template.
class User < ActiveRecord::Base
acts_as_api
api_accessible :only_names do |t|
t.add :first_name
t.add :last_name
end
api_accessible :age_and_first_name, :extend => :only_names do |t|
t.add :age
t.remove :last_name
end
endNow responses with the template age_and_first_name will contain the attributes first_name and age.