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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:28:42+00:00 2026-06-05T08:28:42+00:00

I have a Sinatra web app that I’d very much like to enhance with

  • 0

I have a Sinatra web app that I’d very much like to enhance with streaming updates for certain functions. Right now, though, I’m just trying to learn my way around using streaming data, which I’ve never done before. I have the following simple test code:

In Sinatra:

get '/foo' do
  stream do |out|
    10.times do
      out.puts "foo"
      out.flush
      sleep 1
    end
  end
end

get '/bar' do
  erb :bar
end

In bar.erb:

<body>
  <div class="stream">
    nothing.
  </div>
</body>

<script type="text/javascript" charset="utf-8">
  $(document).ready( function() {
    $.get('/foo', function(html) {
      $(".stream").html(html);
    });
  });
</script>

I’m not surprised that this doesn’t do what I want, which is to pick up each ‘foo’ when it’s written and update the page dynamically. Instead, nothing happens for ~10 seconds and then I get foo foo foo foo foo foo foo foo foo foo foo.

My question is, how in an ERB template (using Ruby, jQuery, or other means) can I pull streamed data as it is provided, instead of blocking until it’s all collected and spitting it all out at once?

  • 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-05T08:28:44+00:00Added an answer on June 5, 2026 at 8:28 am

    Sinatra actions wrap an entire HTTP response cycle – that means it waits until the action finishes before closing the request, at which point the browser considers the data “complete” and “good” for use. All you have created in your code above is a very, very slow Sinatra action.

    The technology you are looking for is Websockets, which are supported by most modern browsers and provide a two-way communications channel between each client and the server. The websocket channel is created by “upgrading” a regular HTTP request. Where clients don’t support web sockets, they may be emulated using techniques such as HTTP Long Polling (wherein a request is left open, without a response, until there is data available – at that point the data is shunted down the response channel, the response channel is closed, and the client is expected to open a new request to get any further data).

    You can get this set up in your Ruby app using EventMachine and EM-Websocket. An alternative is Socky which I believe provides the javascript client as well as the Ruby server.

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

Sidebar

Related Questions

I have a Sinatra app that, boiled down, looks basically like this: class MyApp
I have a portfolio web app that is run on Sinatra using pjax .
I have simple Sinatra app. web.rb: require 'sinatra' get '/' do Hello end Gemfile:*
I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting
I have a Sinatra app, that uses omniauth which constantantly gets this error attack
I have a very simple sinatra site that I'm trying to access via ajax
I have a simple Sinatra app that I will be hosting in tomcat as
I'm building a web app in Sinatra and I have a bunch of files
I have a Web application using Jruby and Sinatra (App Engine) and I want
I'm using a very simple Sinatra app that works well. However, every log message

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.