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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:16:29+00:00 2026-05-27T08:16:29+00:00

I have what seems like a simple problem in my Rails 3.1 app: I

  • 0

I have what seems like a simple problem in my Rails 3.1 app:

I have a series of divs with a class name of ‘feed-row’:

<% @feeds.each do |feed| %>
   <div class="feed-row" data-feedid="<%= feed.id %>">  
   </div>
   <div class="clear">
   </div>
<% end %>

The idea is this:

I will gather all of the divs into a collection, loop over each item, pass its data tag to a page that returns an html fragment, then append that fragment into the appropriate div.

The javascript I have to pull the data looks like this:

<script type="text/javascript" charset="utf-8">
    $(".feed-row").each(function(){     
        $.get("/retrieve/" + $(this).attr("data-feedid"), function(d) {         
            $(this).append(d);
        }); 
    }); 
</script>

Looking at the requests in Chrome’s inspector, I can see that the call out going out fine and returning the HTML fragment I intend:

enter image description here

So, with this HTML fragment, I want to inject it into the current row in my loop.

The Problem Is This

None of my HTML fragments appear on my page – it is simply missing the data pulled via the jQuery .get() method.

When I inspect the DOM elements, it appears that nothing has been injected inside the elements at all:

<div class="feed-row" data-feedid="5"></div>

I am sure I am missing something simple here – why is the data I pull down via jQuery never getting to my DOM elements?

Thanks for any assistance!

  • 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-05-27T08:16:30+00:00Added an answer on May 27, 2026 at 8:16 am

    Because this in the $.get callback is not the same as it is in the .each() callback.

    $(".feed-row").each(function(){    
        var self = this; 
        $.get("/retrieve/" + $(this).attr("data-feedid"), function(d) {         
            $(self).append(d);
        }); 
    }); 
    

    What I did was I referenced the element using the self variable, then used that variable in the $.get callback to reference the element.

    So every iteration of .each() will have a unique self variable, as well as a unique $.get callback that references that the unique self variable in its scope.

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

Sidebar

Related Questions

I have what seems like a simple problem. I have a Spring web app,
This seems like a simple problem: I have a WF4 activity that guides the
this seems like a simple problem. I have a canvas application that I am
I have what seems like it should be a really simple problem, but somehow
Although it seems like a simple problem, I have really come up empty on
Seems like a simple problem: I have an SVN repo inside our firewall. I
I have what seems like a simple arrangement: a list of tags in a
This seems like such a simple question. I have several Edit boxes on my
This seems like it should be so simple, but apparently it isn't. I have
I have an issue that seems like very flaky behavour, is this a problem

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.