I have three models:
class A < ActiveRecord::Base
has_many :bs
end
class B < ActiveRecord::Base
has_one :c
belongs_to :a
end
class C < ActiveRecord::Base
belongs_to :b
end
I want to get json data containing all B's and C's for an A. I tried a number of things similar to:
render json: @as, :include => [:bs => [:include=>[:c]]
but nothing works. What would be a good way to do this.
Refer to
ActiveModel::Serializers::JSON#as_json
to see the options you can pass torender :json
. To quote:It's not necessary to call
to_json
oras_json
directly, asrender :json
does it automatically.Try this:
Try
Try this:
You need to pass in hash instead of array