Skip to content

Calling a scope of a sub resource

fabrik42 edited this page Apr 20, 2011 · 1 revision

Calling a scoped sub resource

You can include scoped associations in your api response by passing the scope chain as a string. Make sure you pass the :as option to name the result of the method chain correctly.

class User < ActiveRecord::Base

  acts_as_api

  api_accessible :include_completed_tasks do |t| 
    t.add "tasks.completed.all", :as => :completed_tasks
  end

end

Tip: This does not only work with associations and their scopes but with all chainable methods.