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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:52:10+00:00 2026-06-13T07:52:10+00:00

I have two applications, App1 and App2. App1 posts a JSON payload to App2

  • 0

I have two applications, App1 and App2. App1 posts a JSON payload to App2 that includes data for a parent and child object. If the parent object already exists in App2, then we update the parent record if anything has changed and create the child record in App2. If the parent object does not exist in App2, we need to first create it, then create the child object and associate the two. Right now I’m doing it like this:

class ChildController
  def create
    @child = Child.find_or_initialize_by_some_id(params[:child][:some_id])
    @child.parent = Parent.create_or_update(params[:parent])

    if @child.update_attributes(params[:child])
      do_something
    else
      render :json => @child.errors, :status => 500
    end
  end
end

Something feels dirty about creating/updating the parent like that. Is there a better way to go about this? 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-06-13T07:52:11+00:00Added an answer on June 13, 2026 at 7:52 am

    As a starting point, you’ll want to create the association in your model, then include accepts_nested_attributes_for on your Parent.

    With the associations created in your model, you should be able to manipulate the relationship pretty easily, because you automatically get a host of methods intended to manage the relationship. For example, your Parent/Child model might look something like this:

    In your Parent model:

    class Parent < ActiveRecord::Base
      has_many :children
      accepts_nested_attributes_for :children
    

    In your Child model:

    class Child < ActiveRecord::Base
      belongs_to :parent
    

    Then, you should be able to build associations in your controller like this:

    def new
        @parent = Parent.children.build
    end
    
    def create
       @parent = Parent.children.build(params[:parent])
    end
    

    The nested_attributes property will then allow you to update attributes of the Child by manipulating the Parent.

    Here is the Rails API on the topic: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

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

Sidebar

Related Questions

I have a Django project that contains two applications App1 and App2 I have
i have two https web applications app1 and app2 installed on two different tomcats
I have two asp.net applications. They are on different domains (i.e., app1.com and app2.com).
I have two applications in codeigniter. Called App1 and App2 under application folder. i
If I have two applications running simultaneously , App1.exe and App2.exe , I want
I have two rails applications App1 and App2 both running on separate URLs but
I have two applications having two different top level windows: App1 -- Window1 App2
I have two applications under tomcat/webapps folder. tomcat/webapps/App1 tomcat/webapps/App2 Both applications share the same
Using tomcat, I have two web-applications i.e app1 and app2. I sent url from
I have two application that need to talk to each other. App1 needs to

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.