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 6104411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:50:21+00:00 2026-05-23T13:50:21+00:00

I’m starting a small Rails project to register iOS devices here at the office,

  • 0

I’m starting a small Rails project to register iOS devices here at the office, just to learn the framework, and I’ve come across the following problem:

Given two models “Device” and “Owner” with the following associations:

class Owner < ActiveRecord::Base
  has_many :devices
end

class Device < ActiveRecord::Base
  belongs_to :owner
  belongs_to :os_version
  belongs_to :device_type
end

Schemas are:

CREATE TABLE "devices" (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 
    "uuid" varchar(255), 
    "imei" varchar(255), 
    "device_type_id" integer, 
    "label" varchar(255), 
    "os_version_id" integer, 
    "owner_id" integer, 
    "created_at" datetime, 
    "updated_at" datetime, 
    "serial" varchar(255)
);
CREATE TABLE "owners" (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 
    "first_name" varchar(255), 
    "last_name" varchar(255), 
    "username" varchar(255), 
    "created_at" datetime, 
    "updated_at" datetime
);

I’m trying to get a controller to eagerly fetch an Owner with all its Devices, so I tried the following:

class OwnerController < ApplicationController

  def list
    @owners = Owner.includes(:devices).all
    respond_to do |format|
      format.xml { render :xml=>@owners } 
      format.any(:json, :html) { render :json => @owners }
    end
  end
end

The controller successfully lists all owners, but the devices are nowhere to be found.

I’ve also tried using default scope in the Owner class, but still no good.

When using rails console, any query using Owner.include(:devices) fails to return device information, but Owner.first.devices has everything in it.

Any ideas on what I might be doing wrong?

Thanks!

  • 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-23T13:50:21+00:00Added an answer on May 23, 2026 at 1:50 pm

    You need to specify that your XML and JSON views should include the devices associations:

    format.xml { render :xml => @owners.to_xml(:include => :devices) } 
    

    Or, in Rails 3, to make things a little simpler:

    class OwnerController < ApplicationController
    
      respond_to :html, :json, :xml
    
      def list
        @owners = Owner.includes(:devices).all
        respond_with @owners, :include => :devices
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.