class Contact < ActiveRecord::Base
has_many :contact_company_profiles, :dependent => :destroy
accepts_nested_attributes_for :contact_company_profiles, :allow_destroy => true
has_many :companies, :through => :contact_company_profiles
has_many :phones, :as => :phoneable, :dependent => :destroy
accepts_nested_attributes_for :phones
end
class ContactCompanyProfile < ActiveRecord::Base
belongs_to :contact
belongs_to :company
end
class Company < ActiveRecord::Base
has_many :contact_company_profiles
has_many :contacts, :through => :contact_company_profiles
has_many :phones, :as => :phoneable, :dependent => :destroy
end
For above specified models i want respond with JSON format through contact controller the code was working fine until i was accessing till companies the below specified command.
@contacts = Contact.find(:id)
respond_to do |format|
format.html
format.js
format.json { render :json=>@contacts.to_json(:include=>[:companies, :phones) }
format.xml { render :xml => @contacts }
end
But now i want json of nested Phone element of company in my contact controller. So kinldy help me in this regard. Thanks
:include=>{:companies=>:phones}