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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:42:17+00:00 2026-06-08T08:42:17+00:00

From my client, I am sending an object that is related to other objects:

  • 0

From my client, I am sending an object that is related to other objects:

var data = {
  "comment": result.comment,
  "doc": {
    "id": result.doc.id
  }
  "site": {
    "url": result.site.url
  }
};

$.ajax({
  url: '/data',
  type: 'POST',
  data: data
});

This gets posted to my /data controller. In the create method, I have this block of code:

def create
  @data = Data.new(params[:data])
  @data.user_id = current_user.id

  respond_to do |format|
    if @data.save
      @doc = Doc.find_or_create_by_id(params[:doc])
      @doc.save
      @site = Site.new(params[:site])
      @site.doc_id = @doc.id
      @site.save

      format.html //stuff
      format.json //stuff
      format.js //stuff
  end
end

I’m curious if I am approaching this problem correctly. For related objects like the one I have, the controller seems to be pretty ‘heavy’.

Are there any other solutions to this problem out there?

EDIT:

Data model:

class Data
  belongs_to :site, :polymorphic => true
  belongs_to :user
end
  • 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-08T08:42:19+00:00Added an answer on June 8, 2026 at 8:42 am

    How does your data model looks like? Do you have assignment methods for all nested attributes?

    def create
      @data = Data.new(params[:data])
      @data.user = current_user
    
      respond_to do |format|
        if @data.save
          @doc = Doc.find_or_create_by_id(params[:doc][:id]) 
          @site = @doc.sites.create(params[:site])
    
          format.html //stuff
          format.json //stuff
          format.js //stuff
      end
    end
    

    You can see more details about Active Record Relations in the Rails Guides.

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

Sidebar

Related Questions

I have a little problem, I'm making project and I'm sending data from client
is there any small working program for recieving from and sending data to client
I'm having a problem sending a java.util.Date object from my C# client to my
I'm sending data from client sockets through a proxy server to an http server.
I am sending a string down from a websockets server to my client that
I'm sending through a socket from java to flex client some data and the
I'm sending from server to clients base64 strings with decoded coordinates of some objects.
Am am successfully parsing and sending JSON values from my client for my server
Sending XML from C# Server and receiving it it in Android Java client This
I'm writing a small (C#) client application that sends data using a TCP/IP connection

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.