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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:39:16+00:00 2026-06-11T17:39:16+00:00

I have a simple rails webservice that exposes a JSON API that allows clients

  • 0

I have a simple rails webservice that exposes a JSON API that allows clients to POST a new record. When the POST is processed, it first creates the referenced record, but also updates some related records at the same time.

@foo = Foo.new(foo_params)
if @foo.save
    related_list = Foo.where(:some_id => foo_params[:list])
    related_list.each do |related|
        # <figure out some stuff here>
        related.update_attributes(stuff)
    end

    # debug spew
    @test = Foo.find(a_related_record_id)
    puts @test.as_json

    format.json { render json: @foo.as_json }
end

I recognize this is a bad two-phase commit pattern, and it’s abusive of the typical REST model, but I inherited this code. I’m going to fix it eventually; this is all part of the “fixing” plan in stages.

This code works perfectly on a local test box. When deployed to Heroku, I put in debug spew that shows the model apparently being updated after update_attributes is called. However, somehow, the model isn’t actually updated. When I check on the “related” records afterwards using a webpage, none of them have been updated with the “stuff” changes. I’m quite baffled by this since the debug spew appears to show the record being updated. Any insights?

Update

One thing I just noticed as I went back through my debug spew is that the updated_at datetime never changes, even though the field in the record appears to have. You can see from the lines below that the call was made around 8:04:15 UTC. Also, I verified that update_attributes was returning true, so there was no error as far as I could tell.

Before update_attributes is called:

←[36m2012-09-20T08:04:15+00:00 app[web.1]:←[0m { “created_at”=>Thu, 20 Sep 2012 00:43:45 UTC +00:00, “somefield”=>””, “id”=>2, “updated_at”=>Thu, 20 Sep 2012 06:22:07 UTC +00:00}

After update_attributes is called:

←[36m2012-09-20T08:04:15+00:00 app[web.1]:←[0m { “created_at”=>Thu, 20 Sep 2012 00:43:45 UTC +00:00, “somefield”=>”10000848364”, “id”=>2, “updated_at”=>Thu, 20 Sep 2012 06:22:07 UTC +00:00}

  • 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-11T17:39:17+00:00Added an answer on June 11, 2026 at 5:39 pm

    After much painstaking research, I managed to figure out the source of the issue, and the fix, but I’m not clear why this is happening. Still, it’s unblocking me for now, and that suffices.

    In the code above, within the

    # <figure out some stuff here> 
    

    block. There was code that I abstracted out in the original question since I didn’t think it was pertinent. Turns out it was. Specifically, there was a line where I was doing a string concatenation:

    some_string << @foo.somestringfield
    

    This one line, for some reason, caused

    related.update_attributes(stuff) 
    

    not to save to the database. This was 100% reproducible (trust me, I tested it about 10 times to be sure). The fix was simple:

    some_string = some_string + @foo.somestringfield
    

    That, seriously, fixed the problem. I did not debug deep into the guts of the in-place concatenation within ruby to determine the root cause, but if someone else ever encounters this problem, well, now you know.

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

Sidebar

Related Questions

I have a fairly simple Rails application that allows users to manage their clients
I have made a simple Rails application that allows people to comment on posts.
I have a really simple Rails application that allows users to register their attendance
I am new to rails and have developed a simple rails application on my
I have a simple rails app that I need to deploy on a Window
I am new to Httparty. I have a simple rails application with its default
I have a simple find in rails 3 that gathers users accounts. Account.where(:user_id =>
I have done simple Rails finds for two tables, but now find that with
I have a simple ruby on rails project that I'm trying to use a
I have a simple rails app that is like an event system which has

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.