Questions tagged [rack]

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Rack is a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

Useful Links

1617 questions
24
votes
5 answers

What is the "env" variable in Rack middleware?

I know a Rack middleware filter is a Ruby class with an initialize and a call method. I know the call method takes an "env" argument. Something like this: class MyFilter def initialize(app) end def call(env) end end My question is: what…
User314159
  • 7,733
  • 9
  • 39
  • 63
24
votes
2 answers

Why is rack response body an array not a string?

a classic hello world example from their doc, class HelloWorld def call(env) return [200, {}, ["Hello world!"]] end end my question is why the third value is [Hello world!"], not "Hello world"? From their doc, The Body must respond to…
ez.
  • 7,604
  • 5
  • 30
  • 29
23
votes
1 answer

Why does Foreman not output some things until I press Control-C?

I just got into rails programming and it looks like there are two programs I can use to run my project locally: rackup and foreman. One difference I noticed is that foreman will not output some things that I would expect to see and I would see if I…
neuromancer
  • 53,769
  • 78
  • 166
  • 223
23
votes
3 answers

Mount Sinatra app inside a rails app and sharing layout

I would like to mount a sinatra application in my rails app. But I would like this one to share the same layout. The iframe could work but do you have any other idea ? Thanks
Mike
  • 5,165
  • 6
  • 35
  • 50
23
votes
2 answers

How to dump an HTTP request from within Sinatra?

Is there a way to dump all incoming requests to a Sinatra application in the exact way the application receives the data? Maybe some sort of Rack middleware?
t6d
  • 2,595
  • 3
  • 26
  • 42
23
votes
2 answers

HTTP/2 Support in Rack / Rails

HTTP/2 is released and supported by all major browsers. There are implementations shipping in major web servers like Apache and nginx. But for us Rubyists, the choices are currently quite limited, it seems. Once upon a time (Dec 2014), Aaron…
ivanreese
  • 2,718
  • 3
  • 30
  • 36
22
votes
4 answers

Streaming data from Sinatra/Rack application

I am trying to stream textual data (XML/JSON) from a Ruby (1.9.1p378) Sinatra (1.0) Rack (1.2.1) application. The suggested solutions (e.g. Is there a way to flush html to the wire in Sinatra) do not seem to work - the server just blocks when I…
yawn
  • 8,014
  • 7
  • 29
  • 34
22
votes
2 answers

Any way to serve gzip assets from heroku?

I'm wondering if there is any way to get the Rails webserver (thin) to serve the *.gz files the asset pipeline creates. As I understand, those have a higher compression level than that of Rack::Deflater, which only works with serve_static_assets…
maletor
  • 7,072
  • 7
  • 42
  • 63
21
votes
4 answers

Rack Error "Rack::Lint::LintError: Response body must respond to each"

I'm going through the tekpub rack tutorial but when I try to run even a basic program in rack i get this error. ERROR Rack::Lint::LintError: Response body must respond to…
AFraser
  • 996
  • 4
  • 13
  • 27
21
votes
1 answer

"No such middleware to insert before: Rack::Lock (RuntimeError)" after upgrading to Rails 4

I'm getting the following error after upgrading to Rails 4: .../ruby-1.9.3-p125/gems/actionpack-4.0.0.rc2/lib/action_dispatch/middleware/stack.rb:125:in 'assert_index': No such middleware to insert before: Rack::Lock (RuntimeError) The offending…
William Denniss
  • 16,089
  • 7
  • 81
  • 124
21
votes
1 answer

"use" keyword/word in Ruby/Rails/Rack code

Recently I happened to see this word in Ruby code, use, when I was going through some code related to goliath, middleware etc. Looks like it is different from include/extend, and require. Can somebody explain why this use keyword exists, and how it…
Amol Pujari
  • 2,280
  • 20
  • 42
20
votes
3 answers

Pass arguments to new sinatra app

Simple question: I want to be able to pass options into my sinatra app in config.ru. How is that possible? My config.ru looks like this: run MyApp But I want to have this in my MyApp class to take arguments: class MyApp < Sinatra::Base def…
Ronze
  • 1,544
  • 2
  • 18
  • 33
20
votes
6 answers

You have already activated rack 1.6.0, but your Gemfile requires rack 1.6.4

Similar to problem with rack 1.3.2. You have already activated rack 1.3.2, but your Gemfile requires rack 1.2.3 -- I'm experiencing You have already activated rack 1.6.0, but your Gemfile requires rack 1.6.4 when attempting to run Rails (4.2) in…
Mark Boulder
  • 13,577
  • 12
  • 48
  • 78
20
votes
4 answers

Adding a custom middleware to Rails 4

I have a Rails 4 sample project (Blog) and I have created a simple middleware called 'request_timer' in config/initializers/request_timer.rb #config/initializers/request_timer.rb class RequestTimer …
sameera207
  • 16,547
  • 19
  • 87
  • 152
20
votes
2 answers

How do I set/get session vars in a Rack app?

use Rack::Session::Pool ... session[:msg]="Hello Rack" EDIT: The word session doesn't seem to resolve. I included the Session pool middleware in my config.ru, and try to set a variable in an ERB file (I'm using Ruby Serve) and it complains…
Sunder
  • 1,445
  • 2
  • 12
  • 22