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

  • Home
  • SEARCH
  • 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 8841379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:42:10+00:00 2026-06-14T10:42:10+00:00

I am developing a simple API for the first time. I have the model

  • 0

I am developing a simple API for the first time. I have the model like this publisher has_many products and products belongs_to publisher. Currently i am displaying all the products including the their each publisher details.Now i want to have publisher details as a separate resource(i dont want to display publisher details in the first request) in other words in the json output to have an attribute that will carry a link to publisher details.How do i do this?Also if anybody have any more complex sample codes for API development you have done in the past, please share with me, because i am trying to learn more.Thank you very much. Here is what i have.

productsController

 respond_to :json, :xml
 def index
 @products=Product.paginate(:page=>params[:page],:per_page => params[:per_page]).all(:include =>  :publisher)
  respond_to do |format|
  format.json { render json: @products.to_json(
    :include=>:publisher) }
  format.xml
   end
   end

json output

    [

 {
    "category_id": null,
    "created_at": "2011-03-25T13:35:16Z",
    "details": "Molestias pariatur consequuntur ut voluptas aperiam facere et et autem ad laudantium ut qui dolorem iste sit ut in dignissimos. Et debitis et et sunt quidem qui est est et",
    "id": 1,
    "product_name": "Velit",
    "publisher_id": 1,
    "updated_at": "2012-11-12T18:45:13Z",
    "publisher": {
        "created_at": "2012-11-12T18:45:13Z",
        "email": "ibrahim@greenholt.net",
        "id": 1,
        "password": "Madelyn Parker",
        "password_confirmation": null,
        "publisher_id": null,
        "updated_at": "2012-11-12T18:45:13Z"
    }
}]
  • 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-06-14T10:42:11+00:00Added an answer on June 14, 2026 at 10:42 am

    https://github.com/josevalim/active_model_serializers is a popular project for customizing the serialization of activemodel objects

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're currently developing a site that uses a simple JSON API (RoR) to populate
I'm developing a simple Android application that would have an action bar on the
I'm developing a simple product catalog in Titanium and I have a TableView with
I'm developing an app (an API) in python and I would like to offer
I am developing a simple web app that uses the Google translation API in
I'm developing a win32 app in the C Programming Language. This is my first
i am developing a simple RESTful API on slim framework. I had no problem
I am developing a simple api which will be used by iphone. Is there
So i've been spending some time developing an iPhone app - it's a simple
This might be a stupid question and/or simple answer, or neither. I am developing

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.