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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:27:37+00:00 2026-06-14T21:27:37+00:00

So I was working on a homework assignment (the SaaS part 2 course on

  • 0

So I was working on a homework assignment (the SaaS part 2 course on edx.org).
Essentially, we have two blog articles, and each article has associated comments. So the goal is to combine two articles into one by creating a third article. That also means, carrying over comments from the first two articles into the third article.

In my code, my first approach is..
assuming the method signature is def merge_with(other_article_id), and self refers to first article, other_article refers to second article, and new_article refers to the newly created third article (note that the new_article is already saved with a primary key assigned)

self.comments do |comment|
  new_article.comments << comment
end
other_article.comments do |comment|
  new_article.comments << comment
end     
new_article.save
debugger

Under debugger, if I do e new_article.comments, it returns empty [] but I am very puzzled as to why that’s the case.

The current work around is

new_article.comments = self.comments + other_article.comments

, and that allows me to finish my homework, but still, its bugs me to no end as to why collection looping approach does not work.

One last question would be.. are there any recommended approach when it comes to reassign child to another parent (in this example reassign comment from one article to another)?

  • 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-14T21:27:39+00:00Added an answer on June 14, 2026 at 9:27 pm

    To solve this I would be tempted to debug inside the loop to see what the value of comment is and to ensure it is actually being called. Shouldn’t ot be: self.comments.each do |comment| …? Perhaps you are missing a call to “each”

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

Sidebar

Related Questions

I am working on a homework assignment where I have to implement a MergeSort
Good day, Stack Overflow. I have a homework assignment that I'm working on this
I am working on a homework assignment involving linked lists. We have to implement
I am new to VHDL, working on a homework assignment. I have a very
I am currently working on a homework assignment where I have to create a
I am working on a homework assignment, and I have almost everything done except
I'm working on a homework assignment for CS1, and I almost have it finished
I am working on a homework assignment, beginning C#. Have to accept input from
I am working on a homework assignment for a class and I have solved
I am working on a homework assignment that deals with binary search trees and

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.