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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:29:02+00:00 2026-05-16T08:29:02+00:00

I have a bit of a complex situation. I am building an iPhone app

  • 0

I have a bit of a complex situation. I am building an iPhone app with a rails backend. There are two model objects, a chat session and a person. They are defined as follows:

class Person < ActiveRecord::Base
belongs_to :chatsession
end


class Chatsession < ActiveRecord::Base
has_many :people
belongs_to :leader, :class_name => "Person"
end

The leader is essentially the main person for that specific chat session. Now from my iPhone app I want to be able to create a Chatsession with the leader in one call (generally network calls are expensive on the iPhone and so I want to avoid creating a Person object and then a session object).

A possible JSON request might look like :

{"chatsession": {"leader": {"name":"mary","device_id":"1111"}}}

On my chatsession controller in the create method I want to be able to suck in this JSON and have it create both a new chat session object and the associated person object.

The relevant code to do this would be:

class ChatsessionController < ApplicationController
     def create
         @chatsession = Chatsession.new(params[:chatsession])   
     end

In my functional test it works with the following code:

 test "should create session" do
       # people(:one) is retrieving from a fixture
       post :create, :chatsession => { :leader => people(:one) }
       assert_response :success
 end

This works great. But to create the equivalent json doesn’t seem to work. It is expecting some kind of Person object and I don’t know how to represent that. I have looked at the following way of solving the issue.

http://www.rogue-development.com/blog2/2009/05/creating-nested-objects-with-json-in-rails/

Is this the best solution or am I missing something?

  • 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-16T08:29:02+00:00Added an answer on May 16, 2026 at 8:29 am

    The post looks like an excellent solution to me.

    Which part are you having trouble with?

    Rails 2.1 and later automatically handles incoming JSON requests. Just make sure that your iPhone app is setting the mime type to json. See post which also discusses testing incoming JSON in posts.

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

Sidebar

Related Questions

The situation is a bit complex. I have a web container which controls another
I have a bit more complex system... I have users model - hasMany Ads
I have a bit of a complex model association: class Company < ActiveRecord::Base has_many
My question is a bit complex, I have a managed bean, possibly A session
I have a bit of a complex situation with WPF Treeview Binding. I have
A bit of a complex problem to describe here: I would like to have
Have a bit of confusion here. I added a few objects from a class
I have a bit of a strange problem. I have a music app that
I have a question for which I suspect the answer is a bit complex.
I have an issue here a bit complex than I'm trying to resolve since

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.