Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7701969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:07:07+00:00 2026-05-31T23:07:07+00:00

I have two models that are associated with each other. Customer has_one :primary_contact And

  • 0

I have two models that are associated with each other.

Customer has_one :primary_contact

And I would like to pull this data out in a json object so that the primary_contact model is associated with the Customer object.

Right now my controller does this :

@customers = current_account.customers.all

respond_to do |format|
  format.json { render :json => @customers.to_json, :layout => false }
end

But I woud like to also include in these customer objects, their primary contact info as well.
How would I go about pulling this information in a associated context so that I get this data in jQuery as :

value.primary_contact.name

Right now, I can pull the json out for the customer object with this :

value.name
value.address
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:07:08+00:00Added an answer on May 31, 2026 at 11:07 pm

    Per the documentation, use the :include option:

    To include associations, use :include.

    konata.to_json(:include => :posts)
    # => {"id": 1, "name": "Konata Izumi", "age": 16,
    #     "created_at": "2006/08/01", "awesome": true,
    #     "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
    #               {"id": 2, author_id: 1, "title": "So I was thinking"}]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, Tweets and TweetsLocations, associated to each other with: class Tweets
I have an application that uses Core Data. I have two data models in
I have two models that are associated. I have an Artist model and a
Say that I have two models- Users and Accounts. Each account can have at
If I have two models that are guaranteed to have a one-to-one correspondence, i.e.
Let's assume I have two gmdistibution models that i obtained using modeldata1=gmdistribution.fit(data1,1); modeldata2=gmdistribution.fit(data2,1); Now
I have two models -- User and Entry -- that are related through a
I have two models (questions and answers) that slightly follow the popular Railscasts :
I have two models User and Admin(with RailsAdmin) that use Devise. I sign in
I have a form that calls on two separate models. My validation works correctly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.