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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:17:07+00:00 2026-06-12T18:17:07+00:00

I have Rails application that needs to retrieve data from a SOAP server outside

  • 0

I have Rails application that needs to retrieve data from a SOAP server outside of my control. It retrieves a list of users with statistics attached to them and returns the data as JSON.

Once that data is retrieved, I need to combine it with data retrieved from my Rails app database.

Once I have the JSON from the SOAP server in hand, I send it up to a Rails controller so that new values can be added to the JSON and then sent back to the view.

My problem is a very simple one. I can’t seem to read and iterate through the JSON once it’s in my controller.

JS from my view stat_data is the JSON received from the SOAP service

window.get_metrics = (stat_data) ->
    update_loading_message 'Getting Metrics'
     console.log stat_data

    $.ajax '/tracking/get_metrics',
        type: "POST"
        data: client_data: stat_data
        dataType: 'json'
        success : (data) ->
            console.log(data)
            # populate_table(data)

Controller

@client_advisors = params[:client_data]
puts @client_advisors

# This is where I would do my other processing / model calls to get new data

render file: 'tracking/metrics_data.json.erb', content_type: 'application/json'

Output of puts @client_advisors

{
"0"=>
{
"personnel_id"=>"1495", 
"personnel_name"=>"John Smith",
"statistic_x"=>"200"
}, 
"1"=>
{
"personnel_id"=>"5266",
"personnel_name"=>"John Candy",
"statistic_x"=>"300"
},
"2"=>{
... etc ...
}
}

tracking/metrics_data.json.erb

[
<%= puts '~~~~~~~~~~~~  PROCESSING JSON' %>
<% @client_advisors.each do |advisor| %>

<%= puts 'advisor::' %>
<%= puts advisor %>
<%= puts 'advisor.inspect::' %>
<%= puts advisor.inspect %>
{   
... This is where my re-generated JSON would go

}
<% end %> 
]

I ridiculously can’t seem to target a personnel_name or personnel_id in my metrics_data.json.erb. It’s outputting each full advisor object just fine in the console… But I’m not sure what I should be using to target the object’s values. I’ve tried advisor.personnel_name (obviously won’t work because the objects are named "0, 1, 2, etc"), advisor['0'], advisor[0], advisor[:0]. None allow me to go a level deeper and retrieve the personnel_name.

Your time is most appreciated!

Solved!

Thanks to @willglynn

"jQuery – somewhat surprisingly – has no mechanism to create JSON. It can parse just fine, but you have to encode it yourself. You can use JSON.stringify , but for ahem certain browsers, you need JSON2.js" – @willglynn

Updated JS

window.get_metrics = (stat_data) ->
    update_loading_message 'Getting Metrics'
     console.log stat_data

    $.ajax '/tracking/get_metrics',
        type: "POST"
        data: client_data: JSON.stringify(stat_data)
        dataType: 'json'
        success : (data) ->
            console.log(data)
            # populate_table(data)

Updated controller

@client_advisors = JSON.parse(params[:client_data])

Updated tracking/metrics.erb.json

<% puts advisor %>
<% puts advisor['personnel_id'] %>
  • 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-12T18:17:08+00:00Added an answer on June 12, 2026 at 6:17 pm

    To answer your question, when Rails gets a POST of JSON content, it transforms the request content into something looking like a form submission. This means that params[] won’t exactly match the original object. To get the original object back, you need to go behind Rails’ back and parse it out of the request directly:

    @client_advisors = ActiveSupport::JSON.decode(request.body.read)
    

    That said, there are a number of things I would change about this code.

    • You have a SOAP server that returns JSON, and this is somehow getting sent to your Rails app. What component does that? Why? Could you cut out the middleman and make Rails talk directly to the SOAP component?
    • You’re generating JSON with string concatenation in an erb template. This is error-prone and tedious. Instead, use render :json => [{ 'key' => 'value' }].
    • You’re putting lots of knowledge into the view. This is a normal place to start, but it’s not ideal. I would probably make a model that encapsulates the response from this SOAP component — not ActiveRecord, just a Ruby object — and make that model responsible for interacting with my other models to have the desired effects.

    That last one is important, since it would let you eliminate your view and reduce the controller to something like:

    @soap_thing = CrazySoapThing.parse(request.body.read)
    @soap_thing.sync
    render :json => @soap_thing.affected_records
    

    See Skinny Controller, Fat Model for more.

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

Sidebar

Related Questions

I have a Rails 3 application that needs to display images from another application.
I have a Ruby on Rails application that needs to find a home in
I have a silverlight application that needs to talk to a rails app to
I have a rails application that has three different types of users and I
I have a rails application that occasionally needs to do very slow network calls
I currently have a Ruby (Rails) application that needs to make a lot of
I'm working on a backbone rails application that needs to poll the server to
I have a rails app that needs a lot of initial data. This data
I have a Rails application with database that is updated from external C++ program.
My Rails app needs to retrieve an updated count from the server every minute.

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.