I have a rails application where I respond to a request by fetching
image urls from various web api calls and need to display them as they
come available. I am able to display all the images once I get them
all, but that causes an unacceptable delay for my user.
One approach I am trying is, from my controller, set an @image
variable, and then pass in a block to the model that retrieves the
image urls. In the block, I call
In the controller, I have:
@query.load_images! do |image|
@image = image
render :update do |page|
page.insert_html :bottom, 'images-div', :partial => 'images'
In my query model, I have:
def load_images! &block
image = get_next_image
In the _images.html.erb, I have:
<%=image_tag @image.url %>
The problem is that with this approach, I get a DoubleRenderError, and
I think this is because render is being called multiple times in the
block call within the loop.
What is the best way to get the effect I need (to load images one at a
time as they become available)?